-
I have 2 problems. THis first one is, i have a Working Model Edition of VB 6 and I jsut got the professional bersion of VB4. Is there any way i an open my VB6 projects in 4? the Working Model Edition does not allow .exes to be made, and the 4 does.
Also....
I am having a problem with integers. I dim them in the FORM load, and they are string variables when i try to add them, it adds them like strings? Any help would be greatly appreciated!
Wrestlecar webmaster
-
Hi, there.
For the second part of your question:
Private Sub Form_Load()
Dim a As String
Dim b As String
Dim c As String
a = 1
b = 3
c = CInt(a) + CInt(b)
Debug.Print CInt(c)
End Sub
Larisa
-
Reply
The problem is that i want them as integers but they are coming out as strings. I have Dimed them as integers in form load, but when i add them it adds them like strings, which i do not want.
-
Show us the code.
Because I can tell you now that they can't "just come out like strings" if you HAVE dimmed them as integers.
-
Below is the code: (A work in progress)
Private Sub calculate_Click()
If fp01 = 1 Then fp01x = 175
If fp01 = 2 Then fp01x = 170
tpr01 = fp01x
If ll01.Value = Checked Then tpr01 = tpr01 + 5
If lml01.Value = Checked Then tpr01 = tpr01 + 5
*tp01 = per01 + tpr01
End Sub
Private Sub Form_Load()
Dim per01 As Integer
Dim fp01 As Integer
Dim tpr01 As Integer
Dim tp01 As Integer
Dim fp01x As Integer
End Sub
The lines with problems are marked with an astrick (*)
-
I've got a suggestion, not sure if it'll work or not, but try this, the variables that you've dimmed, dim them outside the "Subs" so it should look like this:
Dim per01 As Integer
Dim fp01 As Integer
Dim tpr01 As Integer
Dim tp01 As Integer
Dim fp01x As Integer
Private Sub calculate_Click()
If fp01 = 1 Then fp01x = 175
If fp01 = 2 Then fp01x = 170
tpr01 = fp01x
If ll01.Value = Checked Then tpr01 = tpr01 + 5
If lml01.Value = Checked Then tpr01 = tpr01 + 5
tp01 = per01 + tpr01
End Sub
Private Sub Form_Load()
End Sub
Then try it, it should work, if not, then I don't know what's wrong, I didn't thorogly check the code though, cause it's a lil' confusing since I don't completely know what's going on, but try what I said anyways, I hope it helps....
-
If the code you posted is actually what you wrote, then your problem may simply be the scope of your variables. Variables declared with "Dim" inside a procedure are only "alive" while that procedure is running. So, when the Form_Load event is done, all those variables you declared there die with it.
You might try declaring the variables as "Private" in the General Declarations section of the form's code window, and see if that helps your results. That way they will retain any values you assign them as long as your form is running.
Example:
Code:
Option Explicit
'In General Declarations:
Private per01 As Integer
Private fp01 As Integer
Private tpr01 As Integer
Private tp01 As Integer
Private fp01x As Integer
Private Sub calculate_Click()
'Use Select Case instead of If where possible. It is faster
'because condition is tested only once.
Select Case fp01
Case 1
fp01x = 175
Case 2
fp01x = 170
End Select
tpr01 = fp01x
If ll01.Value = Checked Then tpr01 = tpr01 + 5
If lml01.Value = Checked Then tpr01 = tpr01 + 5
tp01 = per01 + tpr01
End Sub
-
Ewww... that explains it then!!!!
All of your variables in the "calculate_click" subroutine are VARIANT.
When you did all your "dim" in the Form_Load those variables lasted for as long as the Form_Load subroutine was running and then they were "BLASTED OUT OF EXISTANCE" the moment it finished.
You need to do it like this :
Code:
Option Explicit ' This stops you from defining a variable
' that hasn't been Dim'ed
Public per01 As Integer
Public fp01 As Integer
Public tpr01 As Integer
Public tp01 As Integer
Public fp01x As Integer
Private Sub calculate_Click()
If fp01 = 1 Then fp01x = 175
If fp01 = 2 Then fp01x = 170
tpr01 = fp01x
If ll01.Value = Checked Then tpr01 = tpr01 + 5
If lml01.Value = Checked Then tpr01 = tpr01 + 5
tp01 = per01 + tpr01
End Sub
-
as for your first question, i don't think you
can open vb6 projects using vb4...
your second question has been well answered
by the others, but if i may add... so that
"Option Explicit" is automatically put, go
to Tools->Options and then check "Require
Variable Declaration". New projects after
setting this will automatically set "Option
Explicit", but you have to manually set this
to your old projects/codes...:):):)
-
Your first problem:
Try deleting the 'Retained' value in the project.vbp file.
-
How do i delete the retained value. I am kinda new to this.
Thanks
-
Open the .vbp file with a text editor, like notepad.
Delete the line that starts with 'RETAINED'. It's near the bottom of the file.
I'm not sure if it works; I only tried it with vb5.
Also, you can't use features of VB6 which are unknown to vb4. So don't use ADO or functions like 'split' or InstrRev.
-
I did that. It still saved as a .vbp
It says "the file is corrupt and cannot be opened" but this is not true because i can open it with 6.
Could someone put step-by step instructions to help me. Thanks!