Dynamically assigning variables...

1. Member
Join Date
Dec 1969
Posts
85

## Dynamically assigning variables...

Is there a more elegant way than below to assign the result of a checkbox post to five variables ?<BR><BR> arrSector=split((request.form("Sectors"),",")<BR>< BR> Dim n, Sector1, Sector2, Sector3, Sector4, Sector5<BR> FOR n = 0 to UBOUND(arrSector)<BR> Select case (n)<BR> case 0<BR> Sector1=arrSector(n)<BR> case 1<BR> Sector2=arrSector(n)<BR> case 2<BR> Sector3=arrSector(n)<BR> case 3<BR> Sector4=arrSector(n)<BR> case 4<BR> Sector5=arrSector(n)<BR> end select<BR> NEXT<BR> <BR> if len(Sector1) &#062; 0 then<BR> Sector1=CInt(Sector1)<BR> else<BR> Sector1="NULL"<BR> end if<BR> <BR> if len(Sector2) &#062; 0 then<BR> Sector2=CInt(Sector2)<BR> else<BR> Sector2="NULL"<BR> end if<BR> <BR> if len(Sector3) &#062; 0 then<BR> Sector3=CInt(Sector3)<BR> else<BR> Sector3="NULL"<BR> end if<BR> <BR> if len(Sector4) &#062; 0 then<BR> Sector4=CInt(Sector4)<BR> else<BR> Sector4="NULL"<BR> end if<BR> <BR> if len(Sector5) &#062; 0 then<BR> Sector5=CInt(Sector5)<BR> else<BR> Sector5="NULL"<BR> end if

2. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: Dynamically assigning variables...

Why the hell are you using separate variables - why not just use an array?!?!?!?<BR><BR>Craig.

3. Senior Member
Join Date
Dec 1969
Posts
1,843

## Yes, and whats up with "Null"?

You are setting the value as the word "Null" You are not setting them to Null. That would be myVar = Null

4. Senior Member
Join Date
Dec 1969
Posts
186

## RE: Dynamically assigning variables...

This will provide the same result.<BR><BR>arrSector=split((request.form("Sect ors"),",")<BR><BR>Dim n<BR>FOR n = 0 to UBOUND(arrSector)<BR><BR>if len(arrSector(n)) &#062; 0 then<BR>arrSector(n)=CInt(arrSector(n))<BR>else<BR >arrSector(n)="NULL"<BR>end if<BR><BR>NEXT

5. Member
Join Date
Dec 1969
Posts
85

## To insert into database....

A DB record can have up to five sectors....<BR><BR>ie. <BR><BR>SQLstr = "Insert into members (sector1......) values (<BR>if Sector1="NULL" then <BR> SQLstr = SQLstr & Sector1 & ","<BR>else<BR> SQLstr = SQLstr & "&#039;" & Sector1 & "&#039;," <BR>end if

6. Senior Member
Join Date
Dec 1969
Posts
293

## Work on the string itself

you have Sectors=1,32,123,,5..... (if I&#039;ve read it correctly) and what you want is an SQL string for insert.<BR><BR><BR>strTemp0 = Sectors<BR>strTemp0="Insert into members (sector1......) values (" & strTemp0 & ")"<BR><BR>strTemp0 = Replace(strTemp0,",,",",&#039;&#039;,")<BR><BR>thi s should give you:<BR><BR>Insert into members (sector1......) values (1,32,&#039;&#039;,...) <BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•