InStr - Zeichenkettensuche
11.06.2016 20:03:35
Nick
ich möchte einen Suchstring innerhalb eines Quellstrings suchen. - Suchstring 'manuell gesetzt' wird gefunden, Suchstring mit Variable hingegen nicht.
Was mache ich falsch? - Irgendeine Definition falsch? - Gruß Nick
Sub Zeichenkette()
Dim Quell_String, Such_String, Q_Text As String
Dim stop_Quartal, Q As Integer
Quell_String = "12F34F"
stop_Quartal = 1
For Q = 4 To stop_Quartal Step -1
Q_Text = ""
If Val(InStr(Quell_String, Q)) > 0 Then
Such_String = Str(Q) + "F"
'Such_String = "2F"
If InStr(Quell_String, Such_String) = Q Then
' INSTR klappt nur wenn Such_String in vorheriger Zeile manuell = "2F" gesetzt ist
Q_Text = "Q" & Q & " fehlerhaft"
Else
Q_Text = "Q" & Q & " okay"
End If
Debug.Print "Q: "; Q, "Quell_string: "; Quell_String, "- Such_String: "; _
Such_String, "- InStr: "; InStr(Quell_String, Such_String), "- Q_Text: "; Q_Text
MsgBox "Quartal: " & Q & " - InStr: " & InStr(Quell_String, Such_String) & " - _
Ergebnis: " & Q_Text
End If
Next Q
Debug.Print "----------------"
End Sub