What's wrong with my code

Results 1 to 2 of 2

Thread: What's wrong with my code

  1. #1
    Charly Guest

    Default What's wrong with my code

    I have a problem with some code I wrote, and I can&#039t find where the answer is. I&#039m a beginner in ASP, database and VBscript so please forgive me if it&#039s an obvious mistake...<BR><BR>The following code works : it displays the title of the table and the fiels names in a table row. (These data come from an Access table.) If the field called phase is empty in all the Access table, there won&#039t be a phase column (or I hope so, anyway !)<BR><BR>&#060;html><BR>&#060;a href="menu.htm">&#060;div align="center">&#060;font face="Times New Roman">Retour&#060;/font>&#060;/div>&#060;/a><BR><BR><BR>&#060;%@ language="VBscript" &#037;&#062;<BR>&#060;% <BR> Dim objConn<BR> Set objConn = Server.CreateObject("ADODB.Connection")<BR> objConn.ConnectionString = "DSN=visionip"<BR> objConn.Open<BR> Dim objRS<BR> Set objRS = Server.CreateObject("ADODB.Recordset")<BR> Dim cat, clas<BR> cat = request.querystring("Cat├ęgorie")<BR> clas = request.querystring("Classe")<BR> Dim StrSQL<BR> StrSQL = "SELECT * From Visionip"<BR> objRS.Open StrSQL, objConn<BR> Dim nb_champ<BR> nb_champ=objRS.fields.count - 1<BR>&#037;&#062;<BR><BR>&#060;%<BR> Function FormatStr(String)<BR> on Error resume next<BR> String = Replace(String, CHR(13), "<BR>") <BR> FormatStr = String<BR> End Function<BR>&#037;&#062;<BR><BR>&#060;div align="center">&#060;font face="Times New Roman" size="+2" color="Navy">&#060;i><BR>&#060;%Dim i&#037;&#062;<BR>&#060;%<BR> for i = 1 to 3<BR> Response.Write(FormatSTR(objRS(i).value))<BR> Next <BR>&#037;&#062;<BR>&#060;/i>&#060;/font><BR>&#060;/div><BR>&#060;font face="Times New Roman" size="1" color="Navy"><BR>&#060;%Response.Write(FormatSTR(o bjRS(4).value))&#037;&#062;<BR>&#060;/font><BR><BR>&#060;%<BR> Dim phase<BR> Do Until objRS.EOF=True<BR> if not objRS("Phase")="" then phase = True<BR> objRS.MoveNext<BR> Loop<BR>&#037;&#062;<BR><BR>&#060;table align="center" cellspacing="0" cellpadding="2" border="1"><BR>&#060;tr><BR>&#060;%For i=5 to 8&#037;&#062;<BR> &#060;td align="center" valign="middle" bgcolor="#320988">&#060;strong>&#060;font color="white"><BR> &#060;%=(objRS(i).name)&#037;&#062;<BR> &#060;/strong>&#060;/font>&#060;/td><BR>&#060;%Next&#037;&#062;<BR>&#060;%<BR> Dim j<BR> if phase = True then j = 10 Else j = 11<BR>&#037;&#062;<BR>&#060;%For i = j to 15&#037;&#062;<BR> &#060;td align="center" valign="middle" bgcolor="#320988">&#060;strong>&#060;font color="white"><BR> &#060;%=(objRS(i).name)&#037;&#062;<BR> &#060;/strong>&#060;/font>&#060;/td><BR>&#060;% Next&#037;&#062;<BR>&#060;/tr><BR><BR>When I had this code, I only get the title and no more table. I think it may come from the fact that ObjRS.EOF is True, but I&#039m really not sure. <BR><BR>&#060;tr><BR> &#060;% For i = 5 to 8&#037;&#062;<BR> &#060;td align="center" valign="middle" bgcolor="#FEB896">&#060;font color="black"><BR> &#060;% FormatSTR(objRS(i).value)&#037;&#062;<BR> &#060;/td><BR> &#060;% Next&#037;&#062;<BR> &#060;% For i = j to 15&#037;&#062;<BR> &#060;td align="center" valign="middle" background="#FEB896"><BR> &#060;% FormatSTR(objRS(i).value)&#037;&#062;<BR> &#060;/td><BR> &#060;% Next&#037;&#062;<BR> &#060;/tr><BR> &#060;/strong>&#060;/font><BR><BR>In both cases, the end of the code is :<BR><BR>&#060;/table><BR><BR>&#060;%<BR> objRS.Close<BR> Set objRS = Nothing<BR> objConn.Close <BR> Set objConn = Nothing <BR>&#037;&#062; <BR>&#060;p><BR>&#060;/html><BR><BR>If someone could help me, this would be great ! I know this is long to read, but I need it ! Thanks again...<BR>

  2. #2
    Stephen Fisher Guest

    Default RE: What's wrong with my code

    In the code<BR><BR>&#060;%<BR>Dim phase<BR>Do Until objRS.EOF=True<BR>if not objRS("Phase")="" then phase = True<BR>objRS.MoveNext<BR>Loop<BR>&#037;&#062;<BR> <BR>You move to EOF.<BR><BR>Remove the line On Error Resume Next while developing and add it back when finished. I think the On Error is for the whole page not just the function, but I may be wrong. If you are at EOF you should get that error message though.<BR><BR>Replace the code I put in here with something like<BR>strSQL2 = "SELECT * FROM Visionip WHERE PHASE = &#039&#039"<BR>objRS2.Open StrSQL, objConn<BR>If not objRS2.EOF Then<BR> phase=true<BR>End If<BR>set objRS2 = nothing<BR><BR><BR><BR><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
  •