Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old August 10th, 2007, 04:34 AM
Phoenix_riser Phoenix_riser is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 225 Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 2 h 28 m 15 sec
Reputation Power: 15
Passing variable then looping

I have an item reference that comes into my program andI then index a table to create say 2 two items.

E.g. Users on say Amazon buys 2 DVDs for 1.

The code might be '241', I then need to split this into two lines in a database to end to the warehouse/courier.

So it would be 'DVD1' and 'DVD2'

I keep getting an error when trying to do it so have split it out without a database as per below and am still having problems.

I checked the variables are passed back as well.


Option Explicit

Private Sub Command1_Click()
'
Dim vitem1 As String
Dim vitem2 As String

Call PrcVariable(vitem1, vitem2)
'
Dim Counter1 As Long
'
For Counter1 = 1 To 2 '2 might become a variable later in life but for now hard code is ok
'
Text1.Text = vitem(Counter1 - 1)
'
Next Counter1
End Sub

Private Sub PrcVariable(vitem1, vitem2)

vitem1 = "1"
vitem2 = "2"

End Sub

Reply With Quote
  #2  
Old August 10th, 2007, 08:32 AM
sanjanah_verma sanjanah_verma is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 190 sanjanah_verma User rank is Corporal (100 - 500 Reputation Level)sanjanah_verma User rank is Corporal (100 - 500 Reputation Level)sanjanah_verma User rank is Corporal (100 - 500 Reputation Level)sanjanah_verma User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 7 h 16 m 13 sec
Reputation Power: 6
Is vitem an array? If yes, where are you filling the array?

Reply With Quote
  #3  
Old August 10th, 2007, 08:42 AM
Phoenix_riser Phoenix_riser is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 225 Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 2 h 28 m 15 sec
Reputation Power: 15
Quote:
Originally Posted by sanjanah_verma
Is vitem an array? If yes, where are you filling the array?


My mistake on the version above.

When it calls it should call with the productID and the look for the
new products...

Code:
Option Explicit

Private Sub Command3_Click()
'
Dim vitem1 As String
Dim vitem2 As String
Dim ItemID As String

ItemID = "241"
Call PrcVariable(ItemID, vitem1, vitem2)
'
Dim Counter3 As Long
'
    For Counter3 = 1 To 2
'
Text1.Text = vitem(Counter3 - 1)
'
   Next Counter3
End Sub

Private Sub PrcVariable(vitem1, vitem2)

'Then here I would use a database to find the 241 code and extract the two codes I want: (in this case ahrd coded for the test version)

vitem1 = "DVD1"
vitem2 = "DVD2"

End Sub

Last edited by Phoenix_riser : August 10th, 2007 at 08:53 AM.

Reply With Quote
  #4  
Old August 10th, 2007, 10:09 AM
sanjanah_verma sanjanah_verma is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 190 sanjanah_verma User rank is Corporal (100 - 500 Reputation Level)sanjanah_verma User rank is Corporal (100 - 500 Reputation Level)sanjanah_verma User rank is Corporal (100 - 500 Reputation Level)sanjanah_verma User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 7 h 16 m 13 sec
Reputation Power: 6
vitem(Counter3 - 1) will still give an error. What is the exact problem/error that you are facing.

Reply With Quote
  #5  
Old August 10th, 2007, 11:00 AM
Phoenix_riser Phoenix_riser is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 225 Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 2 h 28 m 15 sec
Reputation Power: 15
Quote:
Originally Posted by sanjanah_verma
vitem(Counter3 - 1) will still give an error. What is the exact problem/error that you are facing.


The error is "wrong number of arguments"

There is a reason I need the two loops (in reality it is more but 2 will do for the test version)

If the above code works then I can put in the database links, rather than hard coding.

How do I stop that error? vitem(Counter3) has been tried as COunter3, COunter3 - 1 and Counter3 + 1 just to double check with no joy.

Any thoughts?

Reply With Quote
  #6  
Old August 10th, 2007, 11:23 AM
sanjanah_verma sanjanah_verma is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 190 sanjanah_verma User rank is Corporal (100 - 500 Reputation Level)sanjanah_verma User rank is Corporal (100 - 500 Reputation Level)sanjanah_verma User rank is Corporal (100 - 500 Reputation Level)sanjanah_verma User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 7 h 16 m 13 sec
Reputation Power: 6
That error is coming because, the arrary vitem() doesnot have any array elements. You are trying to assign a value from the array element that does not exist. Try some thing like this
vb Code:
Original - vb Code
  1.  
  2. Dim vitem(2) As String
  3.  
  4. Call PrcVariable(vitem1, vitem2)
  5.  
  6. vitem(0) = vitem1
  7. vitem(1) = vitem2
  8.  
  9. Dim Counter1 As Long
  10. '
  11. For Counter1 = 1 To 2 '2 might become a variable later in life but for now hard code is ok
  12. '
  13. Text1.Text = vitem(Counter1 - 1)
  14. '
  15. Next Counter1

Reply With Quote
  #7  
Old August 16th, 2007, 03:18 AM
Phoenix_riser Phoenix_riser is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 225 Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level)Phoenix_riser User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 2 h 28 m 15 sec
Reputation Power: 15
Thank you, working version...

Code:

Option Explicit

Private Sub Command1_Click()

Dim vitem1 As String
Dim vitem2 As String

Dim vitem(0) As String
Dim itemDeal
'
Call PrcVariable(vitem1, vitem2)
'
Dim Counter1 As Long
'
For Counter1 = 1 To 2 '2 might become a variable later in life but for now hard code is ok'
'
                            If (Counter1) = 1 Then
                            itemDeal = vitem1                            End If
'
                            If (Counter1) = 2 Then
                            itemDeal = vitem2
                            End If
'
   Next Counter1
'
End Sub

Private Sub PrcVariable(vitem1, vitem2)

'Then here I would use a database to find the 241 code and extract the two codes I want: (in this case ahrd coded for the test version)

vitem1 = "DVD1"
vitem2 = "DVD2"

End Sub

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Passing variable then looping


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT