Qbasicnews.com

Full Version: Date$ and Time$
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello again... I have a new problem with qbasic...
I warn everyone that you may not understand me well because i'm argentinian and my english is a bit weak.

My problem is this:

I want to make three variables that contain the actual month, the actual time and the actual year.

I made something like this:

Code:
month$ =  LEFT$(DATE$,2)
year$ = RIGHT$(DATE$,4)
aux$ = LEFT$(DATE$, 5)
day$ = RIGHT$(aux$,2)

But when i try to make an operation with this variables i've got "Tipe missmatch" error, becouse QB thinks month$ is a string variable, but it has only numbers.

Is there any other way to get the actual time, year and day? Or is there any way to "convert" a string variable with only contains numbers?

Thanks a lot Wink
Your english is fine. Smile

VAL will convert a string containing a number to a numeric value.

Code:
month = VAL(LEFT$(DATE$, 2))
year = VAL(RIGHT$(DATE$, 4))
aux$ = LEFT$(DATE$, 5)
day = VAL(RIGHT$(aux$, 2))
i tryed your code and i didn't find a problem!
what exactly r u doing when you type run the code?

and u can use mid$ for day so you don't have to make a separate variable for to find day

Code:
month$ = LEFT$(DATE$, 2)
year$ = RIGHT$(DATE$, 4)
day$ = MID$(DATE$, 4, 2)
The error is when i want to make something like:

Code:
a% = month$ - 4

I haven't tried any code yet but thank you both!

EDITED: It works perfectly... Thank you both!
You would then need to do:

a% = VAL(month$) - 4

should work fine :-)