Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

ProbIem comparing  2 strings using INSTR

Posted on 2001-06-19
9
218 Views
Last Modified: 2010-05-02
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(dbversion,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(,appversion,?.?)     ?find the first dot
AppVerpos2=instr(3,appversion,?.?)  ?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
0
Comment
Question by:Gabriel_Brienza
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6207693
You need to format it this way:

    If Format(App.Major, "000") & "." & Format(App.Minor, "000") & "." & Format(App.Revision, "0000") < _
       Format(intMajor, "000") & "." & Format(intMinor, "000") & "." & Format(intRevision, "0000") _
    Then
0
 
LVL 5

Expert Comment

by:gbaren
ID: 6207696
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
0
 
LVL 6

Expert Comment

by:andyclap
ID: 6207778
or even:
if split(appVersion,".")(1)=split(dbVersion,".")(1)
 .. they're the same

0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:Gabriel_Brienza
ID: 6207788
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
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6207830
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

0
 
LVL 5

Accepted Solution

by:
gbaren earned 30 total points
ID: 6207851
How about this:


Private Sub Command2_Click()
Dim AppVersion As String
Dim dbVersion As String
Dim p1 As Integer
Dim p2 As Integer

    AppVersion = "3.4.0"
    dbVersion = "3.4.0"
   
    If VerMajor(AppVersion) <> VerMajor(dbVersion) Then
        MsgBox "Major version different"
    ElseIf VerMinor(AppVersion) <> VerMinor(dbVersion) Then
        MsgBox "Minor version different"
    Else
        MsgBox "They are the same"
    End If

End Sub


Function VerMajor(sVersion As String) As Integer
   
    VerMajor = CInt(Left(sVersion, InStr(sVersion, ".") - 1))
   
End Function


Function VerMinor(sVersion As String) As Integer
Dim p1 As Integer
Dim p2 As Integer

    p1 = InStr(sVersion, ".")
    p2 = InStr(p1 + 1, sVersion, ".")
    VerMinor = CInt(Mid(sVersion, p1 + 1, p2 - p1 - 1))
   
End Function
0
 

Author Comment

by:Gabriel_Brienza
ID: 6208097
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
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 6208619
<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"
0
 

Author Comment

by:Gabriel_Brienza
ID: 6209519
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
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question