ByRef argument type Mismatch

hello, I am having an issue with some code that I am writing. I was hoping that someone can assist me in understanding why I am getting the error that I am getting. Here is the code:

[code]Private Sub SecondUpdate(ByVal Platform As String, ByVal FileName As String)
Dim Line1, Line2, Line3, FullLine, SearchChar As String
Dim Open1, Close1, Open2, Close2 As Integer

If UCase(Platform) = "OPTIPLEX" Then
FullLine = MainSheet.Range("q1").Formula
SearchChar = "["
Call CharSearch(SearchChar, Open1, Open2, FullLine)
SearchChar = "]"
Call CharSearch(SearchChar, Close1, Close2, FullLine)
MainSheet.Range("q5").Value = FileName
ElseIf UCase(Platform) = "DIMENSION" Then
FullLine = MainSheet.Range("q2").Value
Call CharSearch("[", Open1, Open2, FullLine)
MainSheet.Range("q6").Value = FileName
ElseIf UCase(Platform) = "SERVER" Then
FullLine = MainSheet.Range("q3").Value
MainSheet.Range("q7").Value = FileName
ElseIf UCase(Platform) = "WORKSTATION" Then
FullLine = MainSheet.Range("q4").Value
MainSheet.Range("q8").Value = FileName
End If

End Sub

Private Sub CharSearch(ByVal Search As String, ByRef Num1 As Integer, ByRef Num2 As Integer, ByVal MainString As String)

Dim I As Integer
Dim FoundChar As String

For I = 1 To Len(MainString)
FoundChar = Mid(MainString, I, 1)
If FoundChar = Search Then
Num1 = I + 1
I = Len(MainString)
End If
Next I

For I = Num1 To Len(MainString)
FoundChar = Mid(MainString, I, 1)
If FoundChar = Search Then
Num2 = I + 1
I = Len(MainString)
End If
Next I

End Sub[/code]

From SecondUpdate I am calling CharSearch. 2 variables I am passing ByRefand that is where i am getting the error. Does anyone know why?

Thanks

Ducky

Comments

  • Unlike VB.Net, in VB6 you can't define variables like this:
    Dim Open1, Close1, Open2, Close2 As Integer
    because then Open1, Close1 and Open2 will be Variant and only Close2 will be Integer.
    So you need to define your variables like this:
    Dim Open1 As Integer, Close1 As Integer, Open2 As Integer, Close2 As Integer
    Sharbell K. Mouess
  • I noticed in your code, that you use variables that could be reserved words, such as FileName. To be on the safe side, put a prefix on your variables so you know which ones are yours... like strFileName (for a string) or iClose1 (for an integer)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories