Ok, I give up, variable trouble

Results 1 to 4 of 4

Thread: Ok, I give up, variable trouble

  1. #1
    Tara Guest

    Default Ok, I give up, variable trouble

    I have a rather lengthy process, but have narrowed my error down to this part. I have variable passed to the page for the Commodity chosen. I then need to go to the database and look up that commodity&#039s table (there is one table for each one). Each table has 4 columns. Each column has a number. The number chosen depends on the square footage, which is calculated by the script:<BR><BR> &#039figure pack factor based on square footage<BR> If SqFeet&#060;255 then<BR> Column=LEVEL1<BR> ElseIf SqFeet&#062;255 and SqFeet&#060;461 then<BR> Column=LEVEL2<BR> ElseIf SqFeet&#062;461 and SqFeet&#060;767 then<BR> Column=LEVEL3<BR> Else Column=LEVEL4<BR> End If<BR><BR>Now, I then need to query the table to find the number corresponding to the column I need:<BR><BR> Query="select * from &#039&Commodity&&#039 WHERE TEST_WEIGHT=&#039&TestWeight&&#039"<BR> PackFactor=Query("&#039 & Column & &#039")<BR><BR>TestWeight is a number inputted by the user, passed to the page as a variable.<BR>It works fine if that last line is commented out, but when it&#039s not I get :<BR><BR>Microsoft VBScript runtime error &#039 800a000d&#039 <BR><BR>Type mismatch <BR><BR>/bin/calculate_round.asp, line 189 <BR><BR>Can someone help me out here? It won&#039t even work if I tell it which column value to get. All the columns are defined as numbers in the database if that helps.<BR><BR>Thanks.

  2. #2
    Join Date
    Dec 1969

    Default RE: Ok, I give up, variable trouble

    There are a couple of problems, one with query syntax and another in that you never retrieve any records from your table.<BR><BR>Dim Cn, Rs<BR>Set Cn = Server.CreateObject ("ADODB.Connection")<BR>Set Rs = Server.CreateObject ("ADODB.Recordset")<BR>Cn.ConnectionString = "whatever your connection is"<BR>Query="select * from " & Commodity & " WHERE TEST_WEIGHT = " & TestWeight<BR>rs.Open Query, Cn, 3, 3, 1<BR>PackFactor = rs("Column")<BR><BR>

  3. #3
    Join Date
    Dec 1969

    Default More than just variables?

    It&#039s worse than variable trouble. It&#039s fundamentals missing.<BR><BR>You have *several* bugs.<BR><BR>What happens if SqFt is *EXACTLY* 255 or 461? You will get LEVEL4!!<BR><BR>Other bug: Unless LEVEL1, LEVEL2, LEVEL3, LEVEL4 are variables that contain meaningful values, you have nonsense code. By default, each of those will have a null value (a "" if used as a string, zero if used as a number).<BR><BR>The way you build your Query string is nonsense. You are completely messing up your use of &#039 vs. " marks.<BR><BR>Finally, you have something major wrong in that line where you try to get a column value. You are using the same variable name (Query) as the name of the STRING that contains the query. You need to use the name of the RECORDSET object, instead.<BR><BR>So...<BR><BR>********************* *******<BR><BR>&#039figure pack factor based on square footage<BR>If SqFeet&#060;255 then<BR> &nbsp; Column="LEVEL1" &#039 not the quotes!<BR>ElseIf SqFeet&#062;=255 and SqFeet&#060;461 then &#039 note the added =!!!<BR> &nbsp; Column="LEVEL2"<BR>ElseIf SqFeet&#062;=461 and SqFeet&#060;767 then &#039 note the added =!!!<BR> &nbsp; Column="LEVEL3"<BR>Else <BR> &nbsp; Column="LEVEL4"<BR>End If<BR><BR>Query="select * from " & Commodity & " WHERE TEST_WEIGHT=&#039" & TestWeight & "&#039"<BR><BR>Set RS = someConnection.Execute(Query)<BR>...<BR>PackFactor = RS(Column)<BR><BR>******************<BR><BR>That code assumes the Commodity is a VBS variable that somehow *contains* the *name* of the table you want to query. If you actually want to query the table that has the name Commodity, then it&#039s simply:<BR><BR>Query="select * from Commodity WHERE TEST_WEIGHT=&#039" & TestWeight & "&#039"<BR><BR>Finally, that also assumes that TEST_WEIGHT in your DB is a TEXT field. This doesn&#039t really make sense to me. Shouldn&#039t it be a number? If so, you need to drop the &#039...&#039 around the TestWeight value. Thus:<BR><BR>Query="select * from " & Commodity & " WHERE TEST_WEIGHT=" & TestWeight <BR><BR>

  4. #4
    Tara Guest

    Default RE: More than just variables?

    Ok, first of all, to the first replyer, I did define my database connection, just didn&#039t paste it into my post, but thanks.<BR><BR>Thanks to both of you, I totally threw myself off dealing with numbers rather than strings and text - those I have no problem with!<BR><BR>Thanks, though, I&#039m going to go try your suggestions.

Posting Permissions

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