Results 1 to 5 of 5

Thread: variables not holding values

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    145

    variables not holding values

    hello again,

    im transferring a fortran program to VB, and the translator doesnt do great but it does its job. Anyway I have a huge list of public variables, these variables are set right at the beginning of the program (they are specifically set to zero). then the program calls a subroutine and then the subroutine calls another subroutine. When I check the variables some of the variables are coming in as zeros and others (that are set to zero) are coming in "empty".

    Is it possible for something in the program to unset them?

    Can you set the value of the public variables in the public statements?

    Does setting the values in the main program possible effect the way they are transfered to different subroutines since they are public variables?

    thanks guys.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: variables not holding values

    Only variables of the type Variant can be "empty". If the variable is supposed to contain a numeric value its type should reflect that. So they should be declared as Integer or Long for integer valus and Single or Double for floating point values. By declaring the variable of the proper type it will be initilized as 0.

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: variables not holding values

    Can you set the value of the public variables in the public statements?
    no you would need to to it in a proceedure such as form load

    Does setting the values in the main program possible effect the way they are transfered to different subroutines since they are public variables?
    once set they stay the same in all subs until they are changed or reset

    this is for vb6 (vb5 /vba), the forum you have posted in
    vb.net i believe you can set the variable in the declaration
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: variables not holding values

    Quote Originally Posted by Armageddon85
    hello again,

    im transferring a fortran program to VB, and the translator doesnt do great but it does its job. Anyway I have a huge list of public variables
    sounds to me as if you are declaring variables in a single statement like
    Dim var1, var2, var3 as Single

    In Fortran they are probably all singles (I have only used Fortran back in 1979!!!), in VB6 only var3 is a single, the others are Variants!!!!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  5. #5
    New Member
    Join Date
    Oct 2007
    Posts
    1

    Re: variables not holding values

    Have you declared "option explicit" at the beginning just to check you have not misspelt anything? I am no expert but sometimes its the simplest things

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