Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Help with VB 6.0

  • 22-11-2003 9:37pm
    #1
    Registered Users, Registered Users 2 Posts: 1,345 ✭✭✭


    Anyone know why this isnt working?

    Private Sub cmdCalculate_Click()
    'Declare variables
    Dim curDaily, curWeekly, curFortnightly, curTotalPrice, curPriceExVat, curPriceInclVat As Currency
    Dim intDays, intModWeekly, intModFortnightly As Integer
    Const intVat As Integer = 0.2
    Const intDaily As Integer = 1
    Const intWeekly As Integer = 7
    Const intFortnightly As Integer = 14

    'Give variables values
    curDaily = Val(txtDaily)
    curWeekly = Val(txtWeekly)
    curFortnightly = Val(txtFortnightly)
    intDays = Val(txtDays)
    txtPriceExVat = curPriceExVat
    txtPriceInclVat = curPriceInclVat
    intModWeekly = intDays Mod intWeekly
    intModFortnightly = intDays Mod intFortnightly


    If intDays >= 1 < 6 Then
    curPriceExVat = (intDays * curDaily)
    End If

    End Sub

    When i try to calculate no values appear. The daily, weekly and fortnightly values appear when an option button is selected

    Any help would be appreciated as this is really starting to drive me insane


Comments

  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    [b]
    If intDays >= 1 < 6 Then
    curPriceExVat = (intDays * curDaily)
    End If[/b]
    

    Wow...didn't know that was valid syntax in Access....

    Anyway....check that your textbox variables are defined correctly (i.e. you have the correct names in the code). Also, you should assign to .Value or .Text, not just to the variable.

    And I might be missing something, but I can't see the point in having further code after you write to your textboxes, cause it won't change anything.

    jc


  • Registered Users, Registered Users 2 Posts: 1,345 ✭✭✭Squall


    Wow...didn't know that was valid syntax in Access....

    Well im not getting a syntax error so i assume it is :)



    And I might be missing something, but I can't see the point in having further code after you write to your textboxes, cause it won't change anything

    Its part a project about a car rental firm. The values of curDaily etc change as you click on different models of cars. all the user inputs is the number of days the cars needed for then that has to be broken down so the different rates are applied eg 16 days would be fortnightly + 2 daily

    Ive checked all names and theyre right but i still cant figure out why its not working


  • Registered Users, Registered Users 2 Posts: 604 ✭✭✭Kai


    Originally posted by Squall



    'Give variables values
    curDaily = Val(txtDaily)
    curWeekly = Val(txtWeekly)
    curFortnightly = Val(txtFortnightly)
    intDays = Val(txtDays)
    txtPriceExVat = curPriceExVat
    txtPriceInclVat = curPriceInclVat
    intModWeekly = intDays Mod intWeekly
    intModFortnightly = intDays Mod intFortnightly


    If intDays >= 1 < 6 Then
    curPriceExVat = (intDays * curDaily)
    End If

    End Sub


    Try changing to :
    curDaily=Val(txtDaily.text)
    and the same for each of the variables.

    and change

    If intDays >= 1 and intDays < 6 Then


    and see if that works

    also the line
    curPriceExVat = (intDays * curDaily)

    you have to display curPriceExVat somewhere.


  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    Originally posted by Squall
    Ive checked all names and theyre right but i still cant figure out why its not working

    OK. Well, look at the sequence you're doing things in:

    1) You define two local variables : curPriceExVat & curPriceInclVat

    2) You write the values of these uninitialised variables into your textboxes :

    txtPriceExVat = curPriceExVat
    txtPriceInclVat = curPriceInclVat

    3) You calculate the value for one of those values :

    If intDays >= 1 < 6 Then
    curPriceExVat = (intDays * curDaily)
    End If

    So in each and every case, your two textboxes will get written to with the equivalent of the following code :
    Dim x as Currency
    txtMytextbox = x
    

    Hardly surprising that its not going anything ;)

    Calculate the values, then at the end, write the results to the textboxes.

    jc


  • Registered Users, Registered Users 2 Posts: 1,345 ✭✭✭Squall


    Cheers lads i figured it out eventually

    It was the order it was executing was the problem

    7 hours of coding is not good for the brain


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    Originally posted by Squall
    7 hours of coding is not good for the brain

    7 hours? As in less than a standard working day?

    Get used to it....and more.

    Glad you got sorted.

    jc


  • Registered Users, Registered Users 2 Posts: 1,345 ✭✭✭Squall


    Well 7 hours + a full day of college. Plus having insomnia for most of the week.


  • Closed Accounts Posts: 9,314 ✭✭✭Talliesin


    Originally posted by bonkey
    [b]
    If intDays >= 1 < 6 Then
    curPriceExVat = (intDays * curDaily)
    End If[/b]
    

    Wow...didn't know that was valid syntax in Access....

    It's valid syntax, but probably not what was intended. It will first work out whether intDays >= 1 and produce either True or False. Then it will convert that to either -1 or 0 and see if it is < 6, which both of those are, so it will always execute curPriceExVat = (intDays * curDaily)


  • Registered Users, Registered Users 2 Posts: 1,345 ✭✭✭Squall


    ya i thought it looked kinda dodgy alright

    Would you use an and statement to sort that?

    ie

    if intDays => 1 and intDays < 6 then

    ?


  • Registered Users, Registered Users 2 Posts: 629 ✭✭✭str8_away


    One more thing
    Originally posted by bonkey
    'Declare variables
    Dim curDaily, curWeekly, curFortnightly, curTotalPrice, curPriceExVat, curPriceInclVat As Currency
    Dim intDays, intModWeekly, intModFortnightly As Integer

    You only declear curPriceInclVat as Currency rest of them are decleared as Variant
    same as Integers, only intModFortnightly is decleared as Integer.

    you should have write
    Dim curDaily As Currency, curWeekly As Currency, curFortnightly As Currency, curTotalPrice As Currency, curPriceExVat As Currency, curPriceInclVat As Currency
    Dim intDays As Integer, intModWeekly As Integer, intModFortnightly As Integer


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,345 ✭✭✭Squall


    You only declear curPriceInclVat as Currency rest of them are decleared as Variant

    Why declare them as variants?


  • Registered Users, Registered Users 2 Posts: 629 ✭✭✭str8_away


    I don't know why you should declear them as Variant.

    I am not telling you to declear them as Variant.
    I am telling you with what you have written you are delearing them as Variant.
    Unless this is what you intented.


  • Hosted Moderators Posts: 2,563 ✭✭✭Tazzle


    CHEAT!


  • Registered Users, Registered Users 2 Posts: 629 ✭✭✭str8_away


    Originally posted by Mr.Taz
    CHEAT!

    Hi Mr.Taz
    What do you mean by "cheat"?


  • Hosted Moderators Posts: 2,563 ✭✭✭Tazzle


    Excuse my outburst! I was just kiddin with Squall seeing as this is from our programming project. At least, I presume it is.


  • Registered Users, Registered Users 2 Posts: 629 ✭✭✭str8_away


    That's alright. I thought I have made bad comments.


  • Closed Accounts Posts: 9,314 ✭✭✭Talliesin


    Originally posted by Mr.Taz
    CHEAT!
    FWIW, this forum has a policy that defines "cheating", and bans it. Basically it boils down to sitting on your ass and expecting us to do your homework for you. Squall has shown he hasn't done that, and shown he actually wants to learn this stuff rather than get a passing grade.


  • Hosted Moderators Posts: 2,563 ✭✭✭Tazzle


    Eh, sorry if you misunderstood, I was just extracting a bit of urine. No malicious intent.


  • Registered Users, Registered Users 2 Posts: 1,345 ✭✭✭Squall


    FWIW, this forum has a policy that defines "cheating", and bans it. Basically it boils down to sitting on your ass and expecting us to do your homework for you. Squall has shown he hasn't done that, and shown he actually wants to learn this stuff rather than get a passing grade.

    ya, stick it to him :)


    Dim curDaily, curWeekly, curFortnightly, curTotalPrice, curPriceExVat, curPriceInclVat As Currency

    Doesnt this declare them all (ie all variables between dim and as currency as currency?

    If so then all the variables should be Currency and not variants


  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    Nope.

    Dim curDaily, curWeekly, curFortnightly, curTotalPrice, curPriceExVat, curPriceInclVat As Currency

    is effectively the same as :

    Dim curDaily
    Dim curWeekly
    Dim curFortnightly
    Dim curTotalPrice
    Dim curPriceExVat
    Dim curPriceInclVat As Currency

    The unqualified def's will all be defined as variant.


    jc


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,345 ✭✭✭Squall


    ah right

    Only reason i did that was because one of my tutors said it works :)

    Guess ill go back ot my usual then

    Cheers again


  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    It works, alright....its just terribly inefficient.

    jc


  • Registered Users, Registered Users 2 Posts: 1,345 ✭✭✭Squall


    One other Question

    How do you disable right click?

    Were supposed to have text input boxes with a limited number of characters allowed. I can limit characters easily enough i wanna disable right click so they cant paste anything in

    Any ideas?


  • Registered Users, Registered Users 2 Posts: 200 ✭✭DecTenToo




Advertisement