error 9 : subscript out of range を出ないようにするには?

解決


かおる  2003-11-06 22:34:47  No: 80288

はじめまして、VB初心者です。
error 9 : subscript out of range  が**のラインで出てしまいます。
どうしてなのかさっぱり分かりません。ご回答よろしくお願いします。

Private Sub GAP_Next_Button_Click()

Dim BreakPoint() As Boolean
Dim OktoGo As Boolean

Dim a, b, c As String
 a = GAP_A_1_Textbox.Value
 b = GAP_A_2_Textbox.Value
 c = GAP_A_3_Textbox.Value

    If Not BreakPoint(a, b, c) Then**下記のFunctionがおかしいのでしょうか?
        OktoGo = False
        MsgBox "false"
    End If
    
        GAP_Form.Hide
    Weights_Scores_Form.Show
    End If
End Sub

Private Function BreakPoint(a As String, b As String, c As String)

If Not IsNumeric(a) Or Not IsNumeric(b) Or Not IsNumeric(c) Then
    MsgBox "Enter numeric. Please, try again.", vbExclamation + vbOKOnly,
"Input Error"
    BreakPoint = False
    Exit Function

If a <= 0 Then
    MsgBox "Break Point One has to be smaller than BP2, BP3 and 1. Please,
try again.", vbExclamation + vbOKOnly, "Input Error"
    BreakPoint = False
    Exit Function
End If

If b <= a Then
    MsgBox "Break Point One has to be smaller than BP2, BP3 and 1. Please,
try again.", vbExclamation + vbOKOnly, "Input Error"
    BreakPoint = False
    Exit Function
End If

If 1 <= c Then
    MsgBox "Break Point One has to be smaller than BP2, BP3 and 1. Please,
try again.", vbExclamation + vbOKOnly, "Input Error"
    BreakPoint = False
    Exit Function
End If

If a = "" Or b = "" Or c = "" Then
    MsgBox "Enter numeric. Please, try again.", vbExclamation + vbOKOnly,
"Input Error"
    BreakPoint = False
    Exit Function
End If

End Function


k.k  2003-11-06 22:45:14  No: 80289

If Not BreakPoint(a, b, c) Then**下記のFunctionがおかしいのでしょうか?
        OktoGo = False
        MsgBox "false"
    End If
    
        GAP_Form.Hide
    Weights_Scores_Form.Show
    End If
の一番最後のEnd Ifは必要?


simi  2003-11-06 22:50:14  No: 80290

If Not IsNumeric(a) Or Not IsNumeric(b) Or Not IsNumeric(c) Then
    MsgBox "Enter numeric. Please, try again.", vbExclamation + vbOKOnly,
"Input Error"
    BreakPoint = False
    Exit Function

の後にはEnd Ifがないのでは?


かおる  2003-11-07 00:23:44  No: 80291

Simiさん、お返事ありがとうございます。
End ifですが、両方ともコピペミスです。
すいません。


k.k  2003-11-07 00:32:24  No: 80292

正しいプログラム載せて


simi  2003-11-07 01:06:31  No: 80293

Dim a, b, c As String
  ↓
Dim a as String, b as String, c as String

あと関数BreakPoint内のIf文で比較している所は
ちゃんと型を揃えるべきです。


  2003-11-07 02:26:05  No: 80294

Private Sub GAP_Next_Button_Click()

Dim BreakPoint() As Boolean
Dim OktoGo As Boolean

Dim a, b, c As String
 a = GAP_A_1_Textbox.Value
 b = GAP_A_2_Textbox.Value
 c = GAP_A_3_Textbox.Value

    If Not BreakPoint(a, b, c) Then**下記のFunctionがおかしいのでしょうか?
        OktoGo = False
        MsgBox "false"
    End If
    
        GAP_Form.Hide
    Weights_Scores_Form.Show
    
End Sub

Private Function BreakPoint(a As String, b As String, c As String)

If Not IsNumeric(a) Or Not IsNumeric(b) Or Not IsNumeric(c) Then
    MsgBox "Enter numeric. Please, try again.", vbExclamation + vbOKOnly,
"Input Error"
    BreakPoint = False
    Exit Function
End If

If a <= 0 Then
    MsgBox "Break Point One has to be smaller than BP2, BP3 and 1. Please,
try again.", vbExclamation + vbOKOnly, "Input Error"
    BreakPoint = False
    Exit Function
End If

If b <= a Then
    MsgBox "Break Point One has to be smaller than BP2, BP3 and 1. Please,
try again.", vbExclamation + vbOKOnly, "Input Error"
    BreakPoint = False
    Exit Function
End If

If 1 <= c Then
    MsgBox "Break Point One has to be smaller than BP2, BP3 and 1. Please,
try again.", vbExclamation + vbOKOnly, "Input Error"
    BreakPoint = False
    Exit Function
End If

If a = "" Or b = "" Or c = "" Then
    MsgBox "Enter numeric. Please, try again.", vbExclamation + vbOKOnly,
"Input Error"
    BreakPoint = False
    Exit Function
End If

End Function


かおる  2003-11-07 02:29:38  No: 80295

Simiさん、K.K.さんご指摘ありがとうございます。
全コード乗せました。
Dim a as String, b as String, c as String
と直しましたが、まだ同じエラーが出てしまいます。
Simiさんがおっしゃられる「形をそろえる」とはどういうことでしょうか?
具体的に教えていただけますか?


k.k  2003-11-07 02:39:46  No: 80296

型をそろえるというのは、文字列で渡されている引数の比較を数値で比較を行っているからではないでしょうか。
あとエラーが起こっているのは、関数名が悪いみたいです。
BreakPoint以外の関数名にしてみてください。


simi  2003-11-07 02:44:03  No: 80297

文字列変数(a,b,c)を数値と比較しているところです。

あと戻り値の型が定義されてないです。
Private Function BreakPoint(a As String, b As String, c As String)

Private Function BreakPoint(a As String, b As String, c As String) _
As Boolean


魔界の仮面弁士  2003-11-07 04:00:49  No: 80298

> Private Sub GAP_Next_Button_Click()
> Dim BreakPoint() As Boolean

ここで、「BreakPoint」という変数を定義しているので、その下の

>     If Not BreakPoint(a, b, c) Then

という文は、

> Private Function BreakPoint(a As String, b As String, c As String)

という Functionプロシージャではなく、変数の方の BreakPointだと思われていますよ。


かおる  2003-11-08 00:14:28  No: 80299

皆さん、ご助言ありがとうございます。
おかげさまで解決しました。


※返信する前に利用規約をご確認ください。

※Google reCAPTCHA認証からCloudflare Turnstile認証へ変更しました。






  このエントリーをはてなブックマークに追加