Trim Help (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


fearnosurf -> Trim Help (10/31/2005 9:49:05)

How can I trim this array

lsArrDt2 = "3/14/2007 | 4/11 | BC/HH/HS | 3/14/2007 (4, 11 night only)"

to equal this

3/14/2007

currently I'm doing this

jarrdt2 = left(psarrDt2,10)

I would like to know how to trim it based on the | that because a Date can range from 8 characters to 10 I don't want to base it on a number.




rdouglass -> RE: Trim Help (10/31/2005 9:51:55)

quote:

jarrdt2 = left(psarrDt2,10)


jarrdt2 = left(psarrDt2,instr(psarrDt2," ")-1)

That should grab all characters before the first space.




fearnosurf -> RE: Trim Help (10/31/2005 10:03:30)

you're a gentleman and a scholar!
Worked perfectly

Now I have an issue I didn't foresee.

Because I'm returning a date, and they can be 8-10 characters, it throw's my alignment is off.

Here is an example of the returned e-mail:


Arrival Date | # of Club Homes | # of Nights
1. Desired: 3/14/2007 2 4
Alternate: 5/6/2007 4 3
Alternate: 10/17/2007 4 4


My question, is there anyway to make the data have X amount of spaces so my alignment isn't messed with?

here is the code for the mailer to give you an idea of what I'm doing:

lsMailBody2 = lsMailBody2 & "You have requested the following dates:" & chr(13) & chr(13)
lsMailBody2 = lsMailBody2 & "Season:                 " & session("jSeason") & chr(13)
lsMailBody2 = lsMailBody2 & chr(13)
lsMailBody2 = lsMailBody2 & "                 Arrival Date  |" & "  # of Club Homes  |" & "  # of Nights  " & chr(13)
lsMailBody2 = lsMailBody2 & session("jresinfo") & chr(13)
lsMailBody2 = lsMailBody2 & chr(13)
lsMailBody2 = lsMailBody2 & "Confirmation Dates:" & chr(13)
lsMailBody2 = lsMailBody2 & session("jconfirmation") & chr(13)
lsMailBody2 = lsMailBody2 & chr(13)



Session("jresinfo") = "1. Desired:       " & jarrDt11 & "           " & jHomes11 & "                 " & jNights11 & "          " & jaffclub11 & chr(13) &_ 
"   Alternate:     " & jarrDt12 & "           " & jHomes12 & "                 " & jNights12 & "          " & jaffclub12 & chr(13) &_
"   Alternate:     " & jarrDt13 & "           " & jHomes13 & "                 " & jNights13 & "          " & jaffclub13 & chr(13) &_
chr(13) &_


I welcome any advice!




rdouglass -> RE: Trim Help (10/31/2005 10:08:10)

quote:

My question, is there anyway to make the data have X amount of spaces so my alignment isn't messed with?


Always. [;)]

How 'bout something like this:

<%FUNCTION fixDateLengths(dateIn)
tempDateArray = split(dateIn,"/")

FOR i = 0 TO 1
IF len(tempDateArray(i)) = 1 THEN
tempDateArray(i) = "0" & tempDateArray(i)
END IF
NEXT
fixDateLengths = tempDateArray(0) & "/" & tempDateArray(1) & "/" & tempDateArray(2)

END FUNCTION%>

and:

<%jarrdt2 = fixDateLengths(left(psarrDt2,instr(psarrDt2," ")-1))%>

That help any?




fearnosurf -> RE: Trim Help (10/31/2005 10:40:45)

I'm serious, you guys amaze me. Thanks once again!!!! As always that wokred like a charm!


So does anyone know of a good ASP class here in Dallas? My little self taught skills have left me thirsting for much more! Especially when you guys show me what it can really do.




fearnosurf -> RE: Trim Help (11/1/2005 16:57:43)

I would like to format the variable nights similar. I do not have to trim it, but on certain occasions it returns a 2 digit number, or a single digit number. How would I apply this method to that?





rdouglass -> RE: Trim Help (11/1/2005 18:01:26)

To pad it with a leading 0, something like:

len(myVariable) = 1 THEN
myVariable = "0" & myVariable
END IF





fearnosurf -> RE: Trim Help (11/2/2005 9:18:47)

Would you mind helping me comprehend this?


Does len(nights11) = 1 <~~~ len counts the spaces used?




rdouglass -> RE: Trim Help (11/2/2005 9:25:57)

quote:

len counts the spaces used?


You got it. len is short for length. It checks the length of whatever string you pass inside the parens.




fearnosurf -> RE: Trim Help (11/2/2005 9:27:32)

Ah, thank you!

Your code fo course works like a champ, mine however does not :/

Here's what I'm trying to do:
<%
dim i
For i = 0 to 73
if len(jnights(i)) = 1 THEN
jnights(i) = "0" & jnights(i)
END IF
NEXT
%>




rdouglass -> RE: Trim Help (11/2/2005 9:48:14)

quote:

Here's what I'm trying to do:


What are you trying to do? [;)]

To me it looks like you're trying to loop thru an array called jnights that has 74 elements or items. Is that what you're trying?

Also, what currently happens?




fearnosurf -> RE: Trim Help (11/2/2005 10:12:16)

That's exactly what I'm trying to do. I have jnights 11-73 I need to loop through. I also tried the following, but I'm getting page cannot be displayed as well.

<%
dim i
For i = 0 to 73

Select case i
Case 11,12,13,21,22,23,31,32,33,41,42,43,51,52,53,61,62,63,71,72,73
if len(jnights(i)) = 1 THEN
jnights(i) = "0" & jnights(i)
Case Else
END if
End select

Next
%>




rdouglass -> RE: Trim Help (11/2/2005 10:42:09)

quote:

I'm getting page cannot be displayed


Can you turn freindly errors off so we can see the true error?

quote:

For i = 0 to 73


I see what you're trying to do but when you do this:

jnights(i) = "0" & jnights(i)

when i = 73, you're looking for the 74th element of the array jnights. I don't think that's quite what you're trying to do.

Let's back this script up just a minute. What exactly is jnights? Is it now an array or are you trying to request.form("jnights73") or are you trying to access a variable jnights73? When you're calling it from this script, what are you expecting jnights to be?





fearnosurf -> RE: Trim Help (11/2/2005 10:57:38)

Jnights11, jnights12, jnights13, jnights21, jnights22, jnights23 ...continued to jnights73 are all form field values. I'm trying to make them bring back 2 spaces if they are 1 space.


The following code gives me this error.
<%
for i = 0 to 73
Select case i
Case 11,12,13,21,22,23,31,32,33,41,42,43,51,52,53,61,62,63,71,72,73
	if len(jnights & (i)) = 1 THEN
		jnights & (i) = "0" & jnights & (i)
	END if

End select

%>


Microsoft VBScript compilation error '800a03ea'

Syntax error

/OwnersClub/includes/jresinfo.asp, line 713

jnights & (i) = "0" & jnights & (i)
--------^




fearnosurf -> RE: Trim Help (11/2/2005 11:05:44)

To explain further, the jnights 11-73 form fields will return a value of one of thse numbers: 3, 4, 6, 7, 9, 10, 11, 14, 21




fearnosurf -> RE: Trim Help (11/2/2005 11:12:28)

Basically I would like to know how to make a for I statement that will loop a number on the end of a variable.

ie:
jnights = "test"
for i = 0 to 73
response.write(jnights(i))
end.response
next

if I understand this correctly, it should write jnights0, jnights1, jnights2, etc....?

but I get this error when I attempt that
Microsoft VBScript compilation error '800a0400'

Expected statement

/OwnersClub/includes/jresinfo.asp, line 712

end.response
^





fearnosurf -> RE: Trim Help (11/2/2005 11:17:35)

to go on a bit further,

<%
for i = 0 to 73
select case i
case 11
response.write(jnights&(i))
end select
next

%>

with this code it writes 11. when the value of jnights11 is = 4



but this code
<%
jnights = "test"
for i = 0 to 73
response.write(jnights&(i))
next
%>

writes out jnights1 jnights2 jnights3, etc....




rdouglass -> RE: Trim Help (11/2/2005 11:18:24)

quote:

if I understand this correctly, it should write jnights0, jnights1, jnights2, etc....?


Not quite. That would be:

response.write("jnights" & i)

So are these the actual variable names?

jnights0, jnights1, jnights2, etc....?




fearnosurf -> RE: Trim Help (11/2/2005 11:20:11)

the actual variable names are jnights11, jnights12, jnights13, jnights21, jnights22, jnights23, etc... to jnights73




fearnosurf -> RE: Trim Help (11/2/2005 14:37:57)

I went ahead and did this the long way, one day I'd like to learn how to loop a number into a variable so I can save some If...Then space.

<%
IF len(jNights11) = 1 then
jNights11 = " " & jNights11
END IF
IF len(jNights12) = 1 then
jNights12 = " " & jNights12
END IF
IF len(jNights13) = 1 then
jNights13 = " " & jNights13
END IF

IF len(jNights21) = 1 then
jNights21 = " " & jNights21
END IF
IF len(jNights22) = 1 then
jNights22 = " " & jNights22
END IF
IF len(jNights23) = 1 then
jNights23 = " " & jNights23
END IF

IF len(jNights31) = 1 then
jNights31 = " " & jNights31
END IF
IF len(jNights32) = 1 then
jNights32 = " " & jNights32
END IF
IF len(jNights33) = 1 then
jNights33 = " " & jNights33
END IF

IF len(jNights41) = 1 then
jNights41 = " " & jNights41
END IF
IF len(jNights42) = 1 then
jNights42 = " " & jNights42
END IF
IF len(jNights43) = 1 then
jNights43 = " " & jNights43
END IF

IF len(jNights51) = 1 then
jNights51 = " " & jNights51
END IF
IF len(jNights52) = 1 then
jNights52 = " " & jNights52
END IF
IF len(jNights53) = 1 then
jNights53 = " " & jNights53
END IF

IF len(jNights61) = 1 then
jNights61 = " " & jNights61
END IF
IF len(jNights62) = 1 then
jNights62 = " " & jNights62
END IF
IF len(jNights63) = 1 then
jNights63 = " " & jNights63
END IF

IF len(jNights71) = 1 then
jNights71 = " " & jNights71
END IF
IF len(jNights72) = 1 then
jNights72 = " " & jNights72
END IF
IF len(jNights73) = 1 then
jNights73 = " " & jNights73
END IF
%>




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.109375