Results 1 to 13 of 13

Thread: 2 questions

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2000
    Posts
    64
    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

  2. #2
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308
    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

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2000
    Posts
    64

    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.

  4. #4
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    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.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2000
    Posts
    64
    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 (*)


  6. #6
    Guest
    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....


  7. #7
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    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
    ~seaweed

  8. #8
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    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

  9. #9
    Lively Member
    Join Date
    Jun 1999
    Posts
    120
    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...

  10. #10
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    Your first problem:
    Try deleting the 'Retained' value in the project.vbp file.

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Apr 2000
    Posts
    64
    How do i delete the retained value. I am kinda new to this.

    Thanks

  12. #12
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    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.

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Apr 2000
    Posts
    64
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width