質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
VB.NET

Microsoft Visual Basic .NETのことで、Microsoft Visual Basic(VB6)の後継。 .NET環境向けのプログラムを開発することができます。 現在のVB.NETでは、.NET Frameworkを利用して開発を行うことが可能です。

Q&A

解決済

1回答

1932閲覧

星座の判別がしたい (IF文内でエラーでて直りません)

fffu8

総合スコア37

VB.NET

Microsoft Visual Basic .NETのことで、Microsoft Visual Basic(VB6)の後継。 .NET環境向けのプログラムを開発することができます。 現在のVB.NETでは、.NET Frameworkを利用して開発を行うことが可能です。

0グッド

0クリップ

投稿2020/03/09 06:38

編集2020/03/09 06:53

VB.NETでテキストボックスに打たれた生年月日を星座に変えて表示したいのですが、
コードにうまく落とし込むことができません。
あと、プロシージャを使ってやっています。

If文のMonth()とdayの所で波線エラーがでています。
そこをどのように直したらうまくいくのか手助けして頂けたら幸いです。

ーーーーーーーーーコードーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
Public Class Form_Main3_4
Private Sub Button_Display_Click(sender As Object, e As EventArgs) Handles Button_Display.Click

'テキスとボックスに打たれた情報を変数に代入 Dim name As String = Me.TextBox_Name.Text Dim month As String = Me.TextBox_Month.Text Dim day As String = Me.TextBox_Day.Text 'プロシージャにデータを渡す Dim constellation As String = GetConstellation(month, day) MessageBox.Show(name + "さん、あなたは" + constellation + "ですね。") End Sub

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
'Constellation作成
Private Function GetConstellation(ByVal bonth As String, ByVal day As String) As String
Dim constellation As String = String.Empty

If Month() = 1 Then If day < 20 Then constellation = "やぎ座" Else constellation = "みずがめ座" End If ElseIf Month() = 2 Then If day < 20 Then constellation = "みずがめ座" Else constellation = "うお座" End If ElseIf Month() = 3 Then If day < 20 Then constellation = "うお座" Else constellation = "おひつじ座" End If ElseIf Month() = 4 Then If day < 20 Then constellation = "おひつじ座" Else constellation = "おうし座" End If ElseIf Month() = 5 Then If day < 20 Then constellation = "おうし座" Else constellation = "ふたご座" End If ElseIf Month() = 6 Then If day < 20 Then constellation = "ふたご座" Else constellation = "かに座" End If ElseIf Month() = 7 Then If day < 20 Then constellation = "かに座" Else constellation = "しし座" End If ElseIf Month() = 8 Then If day < 20 Then constellation = "しし座" Else constellation = "おとめ座" End If ElseIf Month() = 9 Then If day < 20 Then constellation = "おとめ座" Else constellation = "てんびん座" End If ElseIf Month() = 10 Then If day < 20 Then constellation = "てんびん座" Else constellation = "さそり座" End If ElseIf Month() = 11 Then If day < 20 Then constellation = "さそり座" Else constellation = "いて座" End If ElseIf Month() = 12 Then If day < 20 Then constellation = "いて座" Else constellation = "やぎ座" End If End If Return constellation End Function

End Class

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ttyp03

2020/03/09 06:46

「うまく落とし込むことができません。」のところをきちんと説明してください。 何ができないのか。 あとコードはコードブロックで囲ってください。 ```VBNET コード ```
fffu8

2020/03/09 06:55

If文で星座を判断する書き方の所でエラーが発生しています。 内容を更新しました。
Takumiboo

2020/03/09 07:09

「コードブロックで囲ってください」とは罫線を入れろということではありません。 ttyp03さんのコメントにあるように、 ```VBNET (ここにソースコードを入れる) ``` という形式に質問を編集してください。
guest

回答1

0

ベストアンサー

エラーがたくさん出ているのでは?
型を意識しないといけないです。

VB

1 Dim month As Integer = Integer.Parse(Me.TextBox_Month.Text)

VB

1 Private Function GetConstellation(ByVal month As Integer, ByVal day As Integer) As String

投稿2020/03/09 07:05

x_x

総合スコア13749

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

fffu8

2020/03/09 07:09

すみません、型と違いとスペルミスが原因でした。 ご丁寧にありがとうございます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問