Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 20th, 2009, 05:27 AM
Authorized User
Points: 395, Level: 6
Points: 395, Level: 6 Points: 395, Level: 6 Points: 395, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2007
Location: London, , United Kingdom.
Posts: 73
Thanks: 4
Thanked 0 Times in 0 Posts
Default dynamic variable names

Hi
I am requesting values from form and saving in variables iFName1,iFName2,iFName3...iFName5

Now because some of the variables would be empty so checking them within an if statement and if the are not empty then save in variable FName (that later on store in the database). Because my variabe names are same apart from the last number there for i am trying to create the variable name on runtime but for some reason rather then saving the variable value i am getting the actual variable name in the variable Fname, ANY IDEA WHAT I AM DOING WRONG HERE?

many thanks


Dim iRName,iREmail,iFName1,iFEmail1,iFName2,iFEmail2,i FName3,iFEmail3,iFName4,iFEmail4,iFName5,iFEmail5, FName, FEmail

'' Retrive form fields
iRName = trim(request.Form("iRName"))
iREmail = trim(request.Form("iREmail"))
iFName1 = trim(request.Form("iFName1"))
iFEmail1 = trim(request.Form("iFEmail1"))
iFName2 = trim(request.Form("iFName2"))
iFEmail2 = trim(request.Form("iFEmail2"))
iFName3 = trim(request.Form("iFName3"))
iFEmail3 = trim(request.Form("iFEmail3"))
iFName4 = trim(request.Form("iFName4"))
iFEmail4 = trim(request.Form("iFEmail4"))
iFName5 = trim(request.Form("iFName5"))
iFEmail5 = trim(request.Form("iFEmail5"))



Dim i

For i=1 to 5
if iFName & i <> "" AND iFEmail & i <> "" then
FName= iFName & i
FEmail=iFEmail & i

response.Write(FName)
response.Write(FEmail)
end if




'VALUES GOES IN DB HERE



next
Reply With Quote
  #2 (permalink)  
Old January 20th, 2009, 12:12 PM
Friend of Wrox
Points: 489, Level: 7
Points: 489, Level: 7 Points: 489, Level: 7 Points: 489, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2006
Location: Berkshire, United Kingdom.
Posts: 104
Thanks: 9
Thanked 1 Time in 1 Post
Default

Sheraz,

I've had a play with the code and added a few array variables..

Try amending the below code (works) to your needs..

Code:
<%
Dim iFName(5),iFEmail(5)
'' Retrive form fields
iRName = "name"
iREmail = "email@email.com"
iFName(1) = "name1"
iFEmail(1) = "email1@email.com"
iFName(2) =  "name2"
iFEmail(2) =  "email2@email.com"
iFName(3) = "name3"
iFEmail(3) =  "email3@email.com"
iFName(4 )= "name4"
iFEmail(4) =  "email4@email.com"
iFName(5) = "name5"
iFEmail(5) =  "email5@email.com"
 
Dim i
For i=1 to 5
if iFName(i) <> "" and iFEmail(i) <> "" then
response.Write iFName(i) & "." & iFEmail(i) & "<br>"
end if
next
%>
I am sure one of the more senior members can do a neater job but see how you get on.

Cheers

Aspless
Reply With Quote
  #3 (permalink)  
Old January 20th, 2009, 04:39 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

I don't get that, at all. You have a comment that says
Quote:
'' Retrive form fields
but then you don't actually retrieve any form fields, at all.

HUH?
Reply With Quote
  #4 (permalink)  
Old January 20th, 2009, 04:46 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

ASPLess has the right idea: Use an array.

But you complicated your own life by naming your form fields INCONSISTENTLY. Some of your form field names have a number on the end ("iFName1") and some don't ("ifName").

Okay, we can use your form names, but it would be easier and more consistent if you'd put a number on EVERY ONE of them.
Code:
Dim iRName(5), iREmail(5)
For i = 0 To 5
    If i = 0 Then prefix = "" Else prefix = i 
    iRName(i) = trim(request.Form("iRName" & prefix))
    iREmail(i) = trim(request.Form("iREmail" & prefix))
Next

' and then you can do
For i = 0 To 5
     If iRName(i) <> "" And iREmail(i) <> "" Then
         Response.Write iRName(i) & "::" & iREmail(i) & "<p>" & vbNewLine
     End If
Next
Reply With Quote
The Following User Says Thank You to Old Pedant For This Useful Post:
Sheraz Khan (January 21st, 2009)
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
variable field names philip r VB How-To 2 January 11th, 2009 08:46 PM
generate variable names dinamycally gcorcuera Classic ASP Basics 7 May 21st, 2007 09:53 AM
dynamic variable/object names TheBFJ Excel VBA 2 November 13th, 2006 07:11 AM
Problem with variable names shenku Javascript 2 May 6th, 2005 03:46 PM
Retrieving Dynamic Field Names tdaustin Classic ASP Basics 4 January 12th, 2004 11:10 AM



All times are GMT -4. The time now is 05:32 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.