Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General / January 2005



Tip: Looking for answers? Try searching our database.

Variable reading data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ed Wyche - 30 Jan 2005 19:11 GMT
Is there a way to have

for i=1 to 10
   cboTemp.AddNew rsTemp!Item & i
next

You get and error when it tries to add the the cbobox.
MikeD - 31 Jan 2005 01:19 GMT
> Is there a way to have
>
[quoted text clipped - 3 lines]
>
> You get and error when it tries to add the the cbobox.

That's because the method's name is AddItem, not AddNew.

Signature

Mike
Microsoft MVP Visual Basic

Ed Wyche - 31 Jan 2005 03:54 GMT
That is what I meant.

> > Is there a way to have
> >
[quoted text clipped - 5 lines]
>
> That's because the method's name is AddItem, not AddNew.
MikeD - 31 Jan 2005 04:21 GMT
You're not really being forthcoming with details (or clarity). When you say
that's what you meant, was your code actually using AddItem and you get an
error? If so, telling us what the error is would be a big help. If you meant
that you used AddNew (and got an error, which you would) but meant to use
AddItem and when using AddItem everything is fine, well, then I guess the
problem is solved.  For future reference, copy and paste your code from VB
into the message.  This way, you won't make typos.

Signature

Mike
Microsoft MVP Visual Basic

> That is what I meant.
>
[quoted text clipped - 7 lines]
> >
> > That's because the method's name is AddItem, not AddNew.
Ed Wyche - 31 Jan 2005 04:39 GMT
Sorry about that.

No the problem is still not solved.  I am trying to use the following code
to make it easier.

for i=1 to 10
   cboTemp.AddItem rsTemp!Item & i
next

Instead of

cboTemp.AddItem rsTemp!Item1
cboTemp.AddItem rsTemp!Item2
cboTemp.AddItem rsTemp!Item2
etc.....

> You're not really being forthcoming with details (or clarity). When you say
> that's what you meant, was your code actually using AddItem and you get an
[quoted text clipped - 15 lines]
> > >
> > > That's because the method's name is AddItem, not AddNew.
Jeff Johnson [MVP: VB] - 31 Jan 2005 06:39 GMT
> Sorry about that.
>
[quoted text clipped - 11 lines]
> cboTemp.AddItem rsTemp!Item2
> etc.....

   cboTemp.AddItem rsTemp("Item" & CStr(i))

Drop the ! syntax. It's ancient and inflexible, as this situation
demonstrates.
Ralph - 31 Jan 2005 07:47 GMT
Sorry Jeff, I didn't see your concise answer before responding myself.

-ralph
Compu-Pikachu - 31 Jan 2005 11:07 GMT
[JEFF JOHNSON] Drop the exclamation mark [or "point"] syntax.

[HOSHI PATRICIA FRIEDMAN] I never even knew that existed.  Wow, it's amazing
what you can learn from this newsgroup without even asking questions of your
own!
Ed Wyche - 31 Jan 2005 16:49 GMT
I am getting and error as Type Mismatch
If Not rsTemp("AttractGraphic" & CStr(i)) Then arrAttractGraphic(i) =
rsTemp("AttractGraphic" & CStr(i))

>> Sorry about that.
>>
[quoted text clipped - 17 lines]
> Drop the ! syntax. It's ancient and inflexible, as this situation
> demonstrates.
Ralph - 31 Jan 2005 17:21 GMT
> I am getting and error as Type Mismatch
> If Not rsTemp("AttractGraphic" & CStr(i)) Then arrAttractGraphic(i) =
> rsTemp("AttractGraphic" & CStr(i))

What is the 'value' at the Field named "AttractGraphic'i'".
My guess you got burned by assuming vb would return the default property
'Value'.
Try
  rsTemp( "AttractGraphic" & CStr(i) ).Value
or perhaps even
  CBool(rsTemp("AttractGraphic" & CStr(i) ).Value )

You were warned. <g>
-ralph
Ed Wyche - 31 Jan 2005 18:55 GMT
I forgot to put a ="" in the If statement

>> I am getting and error as Type Mismatch
>> If Not rsTemp("AttractGraphic" & CStr(i)) Then arrAttractGraphic(i) =
[quoted text clipped - 10 lines]
> You were warned. <g>
> -ralph
Ed Wyche - 31 Jan 2005 18:55 GMT
Thanks for the info it worked.

>> I am getting and error as Type Mismatch
>> If Not rsTemp("AttractGraphic" & CStr(i)) Then arrAttractGraphic(i) =
[quoted text clipped - 10 lines]
> You were warned. <g>
> -ralph
Ralph - 31 Jan 2005 07:40 GMT
> Sorry about that.
>
[quoted text clipped - 33 lines]
> > > >
> > > > That's because the method's name is AddItem, not AddNew.

The "!" delimiter is short-hand for returning the value of the "named" item
in a Fields collection. It is convenient but quite specific.

In this context it replaces....
  variantValue = rsTemp.Fields("Item1").Value
where "Item1" becomes an identifier and not subject to modification.

However, in the statement using ...
 variantValue = rsTemp.Fields("Item1").Value, "Item1"is a string parameter
and can be modified before passing to the Fields Item method. So you could
use...
 variantValue = rsTemp("Item" & CStr(i)).Value

Note that the default property of the Item Property is the current value so
you can leave the .value specification off, most of the time. But there can
be a problem, especially when passing an Item, that you end up passing a
reference to the Item and not necessary the value. (A la, "TextBox" vs
"TextBox.Text").

You can also use the position to specify a member of a Fields collection...
   variantValue = rsTemp.Fields.Item(i).Value
   variantValue = rsTemp.Fields(i).Value           ' since the default is
an Item

hth
-ralph
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.