|
-
Nov 19th, 2007, 06:04 PM
#1
Thread Starter
New Member
VB 6 strComp() Help!
I'm just learning VB 6 and I don't know what is wrong, it's working, but not for all values I put in (e.g."tt" or "rr") Thank you
Option Explicit
Private Sub calcFee_Click()
Dim intRez, intMsg As Integer
intRez = 1
Dim strCode As String
Const conButton As String = vbOKOnly + vbInformation + vbDefaultButton1 + vbApplicationModal
strCode = txtCode.Text
Select Case intRez
Case Is = StrComp(strCode, "TC", vbTextCompare)
lblFee.Caption = "The fee is " & "$" & 50
Case Is = StrComp(strCode, "RV", vbTextCompare)
lblFee.Caption = "the fee is " & "$" & 15
Case Is = StrComp(strCode, "OS", vbTextCompare)
lblFee.Caption = "the fee is " & "$" & 5
Case Else
intMsg = MsgBox("Invalid Entry! Try again!", conButton, "List Procedure")
txtCode.SetFocus
txtCode.SelStart = 0
txtCode.SelLength = 2
End Select
End Sub
-
Nov 19th, 2007, 06:53 PM
#2
Addicted Member
Re: VB 6 strComp() Help!
what exactly is it supposed to do? and what exactly is happening that is wrong?
-
Nov 19th, 2007, 07:01 PM
#3
Re: VB 6 strComp() Help!

strComp returns 0 when there is a match so I think you want to do this
Code:
Private Sub calcFee_Click()
Dim intRez, intMsg As Integer
intRez = 0 '1
Dim strCode As String
Const conButton As String = vbOKOnly + vbInformation + vbDefaultButton1 + vbApplicationModal
strCode = txtcode.Text
Select Case intRez
Case Is = StrComp(strCode, "TC", vbTextCompare)
lblfee.Caption = "The fee is " & "$" & 50
Case Is = StrComp(strCode, "RV", vbTextCompare)
lblfee.Caption = "the fee is " & "$" & 15
Case Is = StrComp(strCode, "OS", vbTextCompare)
lblfee.Caption = "the fee is " & "$" & 5
Case Else
intMsg = MsgBox("Invalid Entry! Try again!", conButton, "List Procedure")
txtcode.SetFocus
txtcode.SelStart = 0
txtcode.SelLength = 2
End Select
End Sub
-
Nov 19th, 2007, 07:07 PM
#4
Re: VB 6 strComp() Help!
You could simplify it like this.
Code:
Private Sub calcFee_Click()
Dim intMsg As Integer
Const conButton As String = vbOKOnly + vbInformation + vbDefaultButton1 + vbApplicationModal
Select Case UCase(txtcode.Text)
Case "TC"
lblfee.Caption = "The fee is " & "$" & 50
Case Is = "RV"
lblfee.Caption = "the fee is " & "$" & 15
Case "OS"
lblfee.Caption = "the fee is " & "$" & 5
Case Else
intMsg = MsgBox("Invalid Entry! Try again!", conButton, "List Procedure")
txtcode.SetFocus
txtcode.SelStart = 0
txtcode.SelLength = 2
End Select
End Sub
BTW in your original code intRez does not get defined as an Integer but rather as a Variant. In order for both to be Integers you need to do
Dim intRez As Integer, intMsg As Integer
or
Dim intRez As Integer
Dim intMsg As Integer
-
Nov 20th, 2007, 12:26 AM
#5
Thread Starter
New Member
Re: VB 6 strComp() Help!
Thank you very much for responding me so promptly!
You are right, I have changed to "Dim intRez As Integer, intMsg As Integer"
Using UCase looks much better, I tried that too but it didn't work at all, even using "TC" as an entry value, the MSG box appears.
Also I tried with intRez=0, because I found this too in a VB reference book, but it didn't work at all !!!!
With intRez=1 works good, BUT ONLY if I enter TC,RV,OS and "others for Case Else", I mean the values mentioned in the Select Case statement; if I use other values (e.g, tt as an entry) the value is 50 like in TC. Looks like only the first letter is tested. I'll try it again tomorrow
-
Nov 20th, 2007, 01:06 AM
#6
Re: VB 6 strComp() Help!
conButton should be declared as an Integer, not a String. The constants are all numeric values.
-
Nov 20th, 2007, 01:16 AM
#7
Thread Starter
New Member
Re: VB 6 strComp() Help!
 Originally Posted by penagate
conButton should be declared as an Integer, not a String. The constants are all numeric values.
Constants can be String as well
-
Nov 20th, 2007, 02:27 AM
#8
Thread Starter
New Member
Re: VB 6 strComp() Help!
I didn't wait till tomorrow...and I found the problem!!! The program was saved in VB98 from Visual Studio! How did this make so much trouble? (Please understand that I'm new in VB programming )
Now I saved the same program in the same folder with my other applications, and both variants are working perfect!!!!!: the Ucase and mine (of course this time with intRez=0) Thank you very much MartinLiss!
Thank you to all of you
-
Nov 20th, 2007, 02:56 AM
#9
Re: VB 6 strComp() Help!
 Originally Posted by cami
Constants can be String as well
Yes, but these aren't.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|