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

解決


かおる  2003-11-06 13:34:47  No: 80288  IP: [192.*.*.*]

はじめまして、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 13:45:14  No: 80289  IP: [192.*.*.*]

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 13:50:14  No: 80290  IP: [192.*.*.*]

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-06 15:23:44  No: 80291  IP: [192.*.*.*]

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

編集 削除
k.k  2003-11-06 15:32:24  No: 80292  IP: [192.*.*.*]

正しいプログラム載せて

編集 削除
simi  2003-11-06 16:06:31  No: 80293  IP: [192.*.*.*]

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

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

編集 削除
 2003-11-06 17:26:05  No: 80294  IP: [192.*.*.*]

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-06 17:29:38  No: 80295  IP: [192.*.*.*]

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

編集 削除
k.k  2003-11-06 17:39:46  No: 80296  IP: [192.*.*.*]

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

編集 削除
simi  2003-11-06 17:44:03  No: 80297  IP: [192.*.*.*]

文字列変数(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-06 19:00:49  No: 80298  IP: [192.*.*.*]

> 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-07 15:14:28  No: 80299  IP: [192.*.*.*]

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

編集 削除