Gabriel_Brienza
asked on
ProbIem comparing 2 strings using INSTR
I have the following problem
I would like to compare the 2 strings below.
How can Extract the value between the first dot and the 2nd dot compare the 2 string if equal proceed?
1)AppVersion=?3.4.0
DbVersion=3.4.0
0r
2)AppVersion=?3.14.0
DbVersion=3.14.0
Basically I cannot find a way to compare the 2 strings and if equal proceed
What I thought was:
Dim Appversion as string,dbversion as string
Dim bwrongVersion as Boolean
1)AppVersion=?3.4.0
DbVersion=3.4.0
0r
2)AppVersion=?3.14.0
DbVersion=3.14.0
Bwrongversion= len(Appversion,4)<>len(dbv ersion,4)
If bwrongversion then
MsgBox?Unsuccessfull?
Else
Msgbox?successful?
End if
The problem with this is that if the string is the second example the above will fail.!!!!!!
########################## ########## ########## ########## ##
So I thought
Dim appverPos1 as string,appVerPos2 as string
Dim bwrongVersion as Boolean
AppVerpos1=instr(,appversi on,?.?) ?find the first dot
AppVerpos2=instr(3,appvers ion,?.?) ?find the 2nd dot
DbVerpos1=instr(,DbVersion ,?.?) ?find the first dot
Dbverpos2= instr(3, DbVersion,?.?) ?find the 2nd dot
AppVersionFinal=?????????? ?????????? How can Extract the value between the first dot and the 2nd dot?
DbVersionFinal= ?????????????????????
How can Extract the value between the first dot and the 2nd dot?
Bwrongposition=??????????
Can you help?
Thanks
Gabriel
I would like to compare the 2 strings below.
How can Extract the value between the first dot and the 2nd dot compare the 2 string if equal proceed?
1)AppVersion=?3.4.0
DbVersion=3.4.0
0r
2)AppVersion=?3.14.0
DbVersion=3.14.0
Basically I cannot find a way to compare the 2 strings and if equal proceed
What I thought was:
Dim Appversion as string,dbversion as string
Dim bwrongVersion as Boolean
1)AppVersion=?3.4.0
DbVersion=3.4.0
0r
2)AppVersion=?3.14.0
DbVersion=3.14.0
Bwrongversion= len(Appversion,4)<>len(dbv
If bwrongversion then
MsgBox?Unsuccessfull?
Else
Msgbox?successful?
End if
The problem with this is that if the string is the second example the above will fail.!!!!!!
##########################
So I thought
Dim appverPos1 as string,appVerPos2 as string
Dim bwrongVersion as Boolean
AppVerpos1=instr(,appversi
AppVerpos2=instr(3,appvers
DbVerpos1=instr(,DbVersion
Dbverpos2= instr(3, DbVersion,?.?) ?find the 2nd dot
AppVersionFinal=??????????
DbVersionFinal= ?????????????????????
How can Extract the value between the first dot and the 2nd dot?
Bwrongposition=??????????
Can you help?
Thanks
Gabriel
Try this:
Private Sub Command2_Click()
Dim s1 As String
Dim s2 As String
Dim p1 As Integer
Dim p2 As Integer
s1 = "3.4.0"
s2 = "3.4.0"
p1 = InStr(s1, ".")
p2 = InStr(p1 + 1, s1, ".")
s1 = Mid(s1, p1 + 1, p2 - p1 - 1)
p1 = InStr(s2, ".")
p2 = InStr(p1 + 1, s2, ".")
s2 = Mid(s2, p1 + 1, p2 - p1 - 1)
If s1 = s2 Then
MsgBox "They are equal"
Else
MsgBox "They are not equal"
End If
End Sub
Private Sub Command2_Click()
Dim s1 As String
Dim s2 As String
Dim p1 As Integer
Dim p2 As Integer
s1 = "3.4.0"
s2 = "3.4.0"
p1 = InStr(s1, ".")
p2 = InStr(p1 + 1, s1, ".")
s1 = Mid(s1, p1 + 1, p2 - p1 - 1)
p1 = InStr(s2, ".")
p2 = InStr(p1 + 1, s2, ".")
s2 = Mid(s2, p1 + 1, p2 - p1 - 1)
If s1 = s2 Then
MsgBox "They are equal"
Else
MsgBox "They are not equal"
End If
End Sub
or even:
if split(appVersion,".")(1)=s plit(dbVer sion,".")( 1)
.. they're the same
if split(appVersion,".")(1)=s
.. they're the same
ASKER
Thanks for your quick response
I think I made a mistake in explaining
I want to compare
app.major=3 AND app.Minor=4 or 10-11 etc,
app.revision= I dont need to check
AGAINST DBVERSION.
so if app.major or app.minor have changed I need to
pick that!!
With the example below I think I can only pick app.minor
but not app.major if changes.
I hope I am clear.Thanks guys COULD YOU PLEASE clarify.
Dim AppVersion As String
Dim DbVersion As String
Dim p1 As Integer
Dim p2 As Integer
AppVersion = "3.14.0" (has to be able to pick up
dbVersion=3.14.0" changes in app.major and
app.minor)
p1 = InStr(AppVersion, ".")
p2 = InStr(p1 + 1, AppVersion, ".")
AppVersion = Mid(AppVersion, p1 + 1, p2 - p1 - 1)
p1 = InStr(DbVersion, ".")
p2 = InStr(p1 + 1, DbVersion, ".")
DbVersion = Mid(DbVersion, p1 + 1, p2 - p1 - 1)
If AppVersion = DbVersion Then
MsgBox "They are equal"
Else
MsgBox "They are not equal"
End If
End Sub
I think I made a mistake in explaining
I want to compare
app.major=3 AND app.Minor=4 or 10-11 etc,
app.revision= I dont need to check
AGAINST DBVERSION.
so if app.major or app.minor have changed I need to
pick that!!
With the example below I think I can only pick app.minor
but not app.major if changes.
I hope I am clear.Thanks guys COULD YOU PLEASE clarify.
Dim AppVersion As String
Dim DbVersion As String
Dim p1 As Integer
Dim p2 As Integer
AppVersion = "3.14.0" (has to be able to pick up
dbVersion=3.14.0" changes in app.major and
app.minor)
p1 = InStr(AppVersion, ".")
p2 = InStr(p1 + 1, AppVersion, ".")
AppVersion = Mid(AppVersion, p1 + 1, p2 - p1 - 1)
p1 = InStr(DbVersion, ".")
p2 = InStr(p1 + 1, DbVersion, ".")
DbVersion = Mid(DbVersion, p1 + 1, p2 - p1 - 1)
If AppVersion = DbVersion Then
MsgBox "They are equal"
Else
MsgBox "They are not equal"
End If
End Sub
You can try this:
AppVersion = "3.14.0"
dbVersion="3.14.0"
AppVersion = replace(AppVersion, ".", "")
DBVersion = replace(DBVersion, ".", "")
If AppVersion = DbVersion Then
MsgBox "They are equal"
Else
MsgBox "They are not equal"
End If
AppVersion = "3.14.0"
dbVersion="3.14.0"
AppVersion = replace(AppVersion, ".", "")
DBVersion = replace(DBVersion, ".", "")
If AppVersion = DbVersion Then
MsgBox "They are equal"
Else
MsgBox "They are not equal"
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your very good reply
I have to say that also the other answer from Emoreu was good.
I don't know how to give points to two people at the same time.So I had to choose
Thanks for your help .
Gabriel
I have to say that also the other answer from Emoreu was good.
I don't know how to give points to two people at the same time.So I had to choose
Thanks for your help .
Gabriel
<I don't know how to give points to two people at the same time>
You need to post a new "dummy" question for that like "for emoreau ie 20138142"
You need to post a new "dummy" question for that like "for emoreau ie 20138142"
ASKER
For Emoreau
I checked your code and it's very slicky and good
but it fails there is a change in the app.revision
it should only check major and minor.
Anyway
I think your answer was good
Thanks
Gabriel
I checked your code and it's very slicky and good
but it fails there is a change in the app.revision
it should only check major and minor.
Anyway
I think your answer was good
Thanks
Gabriel
If Format(App.Major, "000") & "." & Format(App.Minor, "000") & "." & Format(App.Revision, "0000") < _
Format(intMajor, "000") & "." & Format(intMinor, "000") & "." & Format(intRevision, "0000") _
Then