Storing Dates inside and array

  • Thread starter Thread starter IntraRELY
  • Start date Start date
I

IntraRELY

Here is my code, but get errors:

Dim installment = 1
Dim beginDate = "1/1/03"
Dim endDate = "1/1/08"
Dim dates(5) As Array
While installment <= 5
endDate = DateAdd(DateInterval.Year, 1, beginDate)
dates.SetValue(couponEndDate, installment)
installment = installment + 1
beginDate = endDate
End While

I even tried to conver the date value to a string, but still recieved
"Object cannot be stored in an array of this type."

TIA,

Steve Wofford
www.IntraRELY.com
 
Hi Steve,

First question, what vb.net version are you using.
My first thougth was that it was without Vs.net what it seems, but seeing
the link you supported you probably are normal using Visual Studio.

Dim installment = 1 is not good code that would probably be
Dim installment as integer = 1
Dim beginDate = "1/1/03" can be
Dim beginDate as string = "1/1/03" but you probably want to do it as a date.

There is not one error in the code but probably 10.

My advice, start with to put in the top of your program
option explicit on
option strict on

Than you sees a lot of this errors direct.

I hope this helps a little bit?

Cor
 
Cor said:
My advice, start with to put in the top of your program
option explicit on
option strict on

I agree (I do this to convince Steve that it is really the way to go) ;-)
 
some things to try
ill modify your code a bit
Dim installment = 1
Dim beginDate as new datetime(cdate("1/1/03"))
Dim endDate as new datetime(cdate("1/1/08"))
Dim dates(5) As datetime
not sure w you are trying to do here
While installment <= 5
endDate = DateAdd(DateInterval.Year, 1, beginDate)
dates.SetValue(couponEndDate, installment)
installment = installment + 1
beginDate = endDate
End While
try this
for i as integer = 1 to 5
dates(i) = dateadd((DateInterval.Year, i, beginDate)
next
 
* "IntraRELY said:
Here is my code, but get errors:

Dim installment = 1
Dim beginDate = "1/1/03"
Dim endDate = "1/1/08"

Declare the variables above in a specific type, 'installment' as
'Integer', the other variables as 'Date'. Use "#1/1/08#" instead of
""1/1/08"".
Dim dates(5) As Array

Why not 'As Date'?
While installment <= 5
endDate = DateAdd(DateInterval.Year, 1, beginDate)
dates.SetValue(couponEndDate, installment)
installment = installment + 1
beginDate = endDate
End While

I even tried to conver the date value to a string, but still recieved
"Object cannot be stored in an array of this type."

Are you sure you know what you want to do?
 
Herfried K. Wagner said:
Declare the variables above in a specific type, 'installment' as
'Integer', the other variables as 'Date'. Use "#1/1/08#" instead
of ""1/1/08"".

I know why you have two (or four) """"" *g* but I'd like to add an example
(just to clarify):

dim begindate as date = #1/1/03#

....and I'd like to add - to Mr. IntraRELY - that this is a date literal and
described in chapter 2.4.6 of the VB language specifications.
Are you sure you know what you want to do?

Not so sarcastic, HKW! ;-))
 
Hi Armin,
Not so sarcastic, HKW! ;-))
I dont think this is sarcasme, I think in this case it is a good question,
and while writing this, maybe it would have be better

Can you explain us what you want to do?

But as I started, in this case I think it is not wrong.

Just a thought

Cor
 
Cor said:
Hi Armin,

I dont think this is sarcasme, I think in this case it is a good
question, and while writing this, maybe it would have be better

Can you explain us what you want to do?

But as I started, in this case I think it is not wrong.

Just a thought

Cor

Ah c'mon ... missed the smiley? If I had written such a sentence few weeks
ago, I probably would have been stoned to death by some hypersensitive
people. :)
 
Hi Armin,

I did not mis it, but did write it with the same reason as you did this
morning with my post about option strict, :-))

(not for you)

I hope you understand this.

Cor
 
* "Armin Zingler said:
I know why you have two (or four) """"" *g* but I'd like to add an example
(just to clarify):

LOL... I use """ as a markup for strings or characters, that's why I
typed two """ characters.
dim begindate as date = #1/1/03#

...and I'd like to add - to Mr. IntraRELY - that this is a date literal and
described in chapter 2.4.6 of the VB language specifications.


Not so sarcastic, HKW! ;-))

;-))
 
* "Armin Zingler said:
Ah c'mon ... missed the smiley? If I had written such a sentence few weeks
ago, I probably would have been stoned to death by some hypersensitive
people. :)

I apologize for being so rude. Shame on me.

;-)
 
Back
Top