[VBScript] Aanroepen functie-uitkomst

Pagina: 1
Acties:

  • Reveller
  • Registratie: Augustus 2002
  • Laatst online: 05-12-2022
situatie
Ik ben bezig met een eigen weblogje te bouwen en heb hiervoor o.a. de volgende functie geschreven.

ASP.NET Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function showPosts()
    sql="select top 3 * from tblWebLog order by dtmDateStamp desc" 
    makeRS(SQL)

    sHTML = ""
    do while not rs.EOF
        strLabel=rs("strLabel")
        strText=rs("strText")
        sHTML = ""
        sHTML = sHTML & "<table border=0 width=90>"
        sHTML = sHTML & "<tr><td bgcolor='#DDDDDD'>"
        sHTML = sHTML & strLabel
        sHTML = sHTML & "<tr><td>"
        sHTML = sHTML & strText
        sHTML = sHTML & "</td></tr></table>"
        rs.movenext
    loop
    rs.close
    Response.Write(sHTML)
end function

probleem
Als ik - waar dan ook in mijn pagina - deze functie aanroep (dwv. showPosts()), wordt de gegenereerde tabel BOVENAAN de html pagina weggeschreven. Ik vermoed dat het met de Response.Write te maken heeft; blijkbaar wordt dit - ook al wordt de functie pas onderaan de pagina aangeroepen - geparsed.

vermoeden hoe op te lossen
Ik denk dat ik ipv. Response.Write(sHTML) iets als Return(sHTML) moet neerzetten...

Toen ben ik eens wat verder gaan kijken, en het blijkt dat met vbscript meegekomen functies als Now() precies zo werken: de datum verschijnt op de html pagina precies waar ik in de ASP source de functie Now() aanroep.

gevraagd
Wie kan mij helpen mijn functie aan te passen zodat wanneer ik deze aanroep, sHTML ook op DIE plek in de pagina wordt weggeschreven?

Ik hoop dat ik duidelijk ben geweest in mijn vraagformulering...

"Real software engineers work from 9 to 5, because that is the way the job is described in the formal spec. Working late would feel like using an undocumented external procedure."


  • Woudloper
  • Registratie: November 2001
  • Niet online

Woudloper

« - _ - »

Wellicht omdat je de Recordset niet opent, maar ik heb een vermoeden dat je dat moedwillig hebt weggelaten...

Zelf doe ik het ook vaak op deze manier en krijg het nooit bovenin (boven de HTML definitie :?) terug...

Werk je overigens met option explicit, zodat je kan zien dat de fout wellicht ergens anders door wordt veroorzaakt!?

Wat je ook nog kan proberen is om op verschillende plaatsen gewoon response.write te doen zodat je kan debuggen

  • Reveller
  • Registratie: Augustus 2002
  • Laatst online: 05-12-2022
Woudloper, de functie om de recordsets uit de dbase te openen werkt opzich perfect. Er zitten nog wat andere checks in, maar samen met het openen van de recordset heb ik deze gegelaten omdat ze niet van belang zijn voor de vraag.

Ik heb zelf ook al vaak met response write gewerkt, en dat werkte ook perfect:

ASP.NET Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<html>
<body>
Geachte lezer, pas op want hier volgen mijn weblog posts:<br>
<br>

<%
   sql="select top 3 * from tblWebLog order by dtmDateStamp desc" 
    makeRS(SQL)

    sHTML = ""
    do while not rs.EOF
        strLabel=rs("strLabel")
        strText=rs("strText")
        sHTML = ""
        sHTML = sHTML & "<table border=0 width=90>"
        sHTML = sHTML & "<tr><td bgcolor='#DDDDDD'>"
        sHTML = sHTML & strLabel
        sHTML = sHTML & "<tr><td>"
        sHTML = sHTML & strText
        sHTML = sHTML & "</td></tr></table>"
        rs.movenext
    loop
    rs.close
    Response.Write(sHTML)
%>
</body>
</html>


Maar de vraag is nu: waarom werkt het volgende niet?

ASP.NET Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<%
' functies gebruikt in deze pagina

function showPosts()
    sql="select top 3 * from tblWebLog order by dtmDateStamp desc" 
    makeRS(SQL)

    sHTML = ""
    do while not rs.EOF
        strLabel=rs("strLabel")
        strText=rs("strText")
        sHTML = ""
        sHTML = sHTML & "<table border=0 width=90>"
        sHTML = sHTML & "<tr><td bgcolor='#DDDDDD'>"
        sHTML = sHTML & strLabel
        sHTML = sHTML & "<tr><td>"
        sHTML = sHTML & strText
        sHTML = sHTML & "</td></tr></table>"
        rs.movenext
    loop
    rs.close
    Response.Write(sHTML)
end function
%>
<html>
<body>
Geachte lezer, pas op want hier volgen mijn weblog posts:<br>
<br>

<% showPosts() %>
</body>
</html>


Je zou denken dat de html die naar de client gestuurd wordt, er als volgt uit zou zien:

HTML:
1
2
3
4
5
6
7
<html>
<body>
Geachte lezer, pas op want hier volgen mijn weblog posts:<br>
<br>
  <table meuk met weblog posts>
</body>
</html>


Hij ziet er echter zo uit:

HTML:
1
2
3
4
5
6
7
  <table meuk met weblog posts>
<html>
<body>
Geachte lezer, pas op want hier volgen mijn weblog posts:<br>
<br>
</body>
</html>


Om de een of andere reden wordt de Response.Write die ik in de showPosts() functie heb zitten, geparsed VOORDAT de rest van de pagina gegenereerd wordt. De vraag is hoe dit kan.

"Real software engineers work from 9 to 5, because that is the way the job is described in the formal spec. Working late would feel like using an undocumented external procedure."


  • Crazy D
  • Registratie: Augustus 2000
  • Laatst online: 10:06

Crazy D

I think we should take a look.

Controleer je html output eens. (en wordt die tekst ook daadwerkelijk boven in de source geprint, of alleen getoont? Als je binnen tabel een tekst uitspuugt, maar je vergeet <tr><td> </td></tr> eromheen te zetten, wordt de tekst ook boven in de pagina getoont).
De response.write zal nooit eerder uitgevoerd worden dan het moment waarop je de functie aanroept, dus dat is het probleem niet.

[edit]
hmmm das wel wazig, als die tabelmeuk echt bovenin de source zelf komt te staan, denk ik dat je die functie toch al stiekum ergens aanroept.... is die laatste ASP code die je poste, de volledige pagina?

Exact expert nodig?


  • Reveller
  • Registratie: Augustus 2002
  • Laatst online: 05-12-2022
Om verdere verwarring te voorkomen, hierbij het probleem met code. Ik heb de pagina wat aangepast maar het idee blijft gelijk.

het is niet mijn bedoeling dit forum te vervuilen met code, maar ik denk dat ik een uitzondering kan maken om mijn probleem te illustreren. Volgens mij moet de oplossing heel eenvoudig zijn, maar zonder code is het wellicht moeilijk uitleggen

Hieronder staan 4 bestanden:

1. lemonlime.asp
2. lemonlime.tpl (template betand)
3. template_cls.asp (template class)
4. de html output van dit alles

De werking spreekt denk ik voor zich: lemonlime.asp haalt lemonlime.tpl op en gonstrueert mbv. de template class de output die naar de client gaat. Het probleem zit in lemonlime.asp, wederom de functie showPosts(). Waarom wordt de string "hier worden de weblog posts uit de dbase gehaald" niet op de plaats van "body" neergezet maar helemaal bovenin de pagina?

Zoals je ziet in regel 20 van lemonlime.asp (het bestand hieronder) en regel 136 van de output (bestand 4), werkt het aanroepen van de functie Now() wel correct - de tijd wordt niet bovenaan de pagina gezet, maar keurig op de plek waar ik hem wil hebben. Waarom gebeurt dat niet als ik de functie showPosts() aanroep?!

1. lemonlime.asp
ASP.NET Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<!--#include file="template_cls.asp"-->
<%
function showPosts()
    Response.Write("hier worden de weblog posts uit de dbase gehaald")
end function

dim objTemplate
const TMPLDIR = ""
set objTemplate = new template_cls
with objTemplate
    .TemplateFile = TMPLDIR & "lemonlime.tpl"
    .AddToken "siteName", 1, "Fluffy Convicts Weblog"
    .AddToken "calendar", 1, "hier komt later een kalender"
    .AddToken "tagLine", 1, "The journey is the reward"
    .AddToken "cascadingStyleSheet", 1, .loadFile("lemonlime.css", 1)
    .AddToken "title", 1, "title"
    .AddToken "body", 1, "<body>"
    .AddToken "bodyText", 1, showPosts()
    .AddToken "navigatorLinks", 1, "link1<br>link2<br>link3"
    .AddToken "lastUpdateString", 1, Now()
    .AddToken "Year", 1, DatePart("yyyy", Date)
    .parseTemplateFile
end with
set objTemplate = nothing
%>


2. lemonlime.tpl
HTML:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>{siteName} : {title}</title>
    {meta} {cascadingStyleSheet} {javaScript} 
  </head>
{body}
<table width="780" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr> 
    <td width="28">[img]"img/top1.gif"[/img]</td>
    <td width="722">
      <table width="722" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="11">[img]"img/topBG.gif"[/img]</td>
          <td width="711" valign="top" background="img/topBG.gif"> 
            <p>[img]""[/img]<br><b><font size="+2">{siteName}</font></b>
            <i>{tagLine}</i></p>
          </td>
        </tr>
      </table>
    </td>
    <td width="30">[img]"img/top3.gif"[/img]</td>
  </tr>
  <tr> 
    <td width="28" background="img/leftBG.gif" valign="top"><img src="img/leftBG.gif" 
width="28" height="20" alt="-"></td>
    <td width="722" bgcolor="#FFFFFF"> 
      <table width="722" border="0" cellspacing="0" cellpadding="0" align="center">
        <tr> 
          <td width="120" valign="top"> 
            <table width="120" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td colspan="3" height="10">[img]""[/img]</td>
              </tr>
              <tr> 
                <td width="10">[img]""[/img]</td>
                <td> 
                  <p><b><font size="-2">Navigation<br>
                  </font></b><font size="-2">{navigatorLinks}</font></p>
                </td>
                <td width="10">[img]""[/img]</td>
              </tr>
              <tr>
                <td colspan="3" height="10">[img]""[/img]</td>
              </tr>
            </table>
          </td>
          <td valign="top" width="100%"> 
            <table width="100%" border="0" cellspacing="0" cellpadding="11">
              <tr> 
                <td><p>{bodytext}</p></td>
              </tr>
            </table>
          </td>
          <td width="160" valign="top"> 
            <table width="160" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td colspan="3" height="10">[img]""[/img]</td>
              </tr>
              <tr> 
                <td width="10">[img]""[/img]</td>
                <td> 
                  <p>{calendar}</p>
                </td>
                <td width="10">[img]""[/img]</td>
              </tr>
              <tr>
                <td colspan="3" height="10">[img]""[/img]</td>
              </tr>
            </table>
          </td>       
        </tr>
      </table>
    </td>
    <td width="12" align="right" valign="top" background="img/rightBG.gif">
[img]"img/rightBG.gif"[/img]</td>
  </tr>
  <tr> 
    <td>[img]"img/bottom1.gif"[/img]</td>
    <td background="img/bottomBG.gif">[img]"img/bottomBG.gif"[/img]</td>
    <td>[img]"img/bottom3.gif"[/img]</td>
  </tr>
</table>
<p align="center"> <font size="-2">Last update: {lastUpdateString}<br>
  Copyright {year} {siteName} </font></p>
<p align="center">"this is a reveller site"
</body>
</html>


3. template_cls.asp
ASP.NET Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<%
'--- --- ---
' template_cls.asp
'
' version 1.5
'---- ---- ----
' (c)2000 - 2002 James Q. Stansfield (jqs@iridani.net)
' This code is free to be used by anyone provided that the copyright is retained in the script.
' This code may be redistributed provided the copyright is retained in the script.
'----- ----- -----
option explicit
const cTEMPLATE_VERSION = 1.5

'Define our token type constants
const STRINGVARIABLE = 1
const INCLUDEANDPARSE = 2
const INCLUDEANDNOPARSE = 3
const PARSESTRING = 5
const PARSEARRAY = 6

class template_cls
    '---
    'Declarations
    '---
    private gstrTemplateFile
    private gobjTokens
    private gblnReturn
    private gstrHTML
    private gstrOpenTag
    private gstrCloseTag
    '---
    'Create & Destroy Methods
    '---
    private sub Class_Initialize
        set gobjTokens = createobject("Scripting.Dictionary")
        gobjTokens.CompareMode = 1
        gblnReturn = False
        gstrHTML = ""
        gstrOpenTag = "{"
        gstrCloseTag = "}"
    end sub
    '---
    private sub Class_Terminate
        set gobjTokens = nothing
    end sub
    '---
    'Properties
    '---
    public property let TemplateFile(inString)
        gstrTemplateFile = inString
    end property
    '---
    public property let OpenTag(inString)
        gstrOpenTag = inString
    end property
    '---
    public property let CloseTag(inString)
        gstrCloseTag = inString
    end property
    '---
    public property let CI(inBool)
        if vartype(inbool) = 11 then
            if inBool then
                inBool = 1
            else
                inBool = 0
            end if
            gobjTokens.CompareMode = inBool
        end if
    end property
    '---
    'Subroutines
    '---
    public sub AddToken(inToken, inType, inData)
        if len(inToken) > 0 then
            if gobjTokens.Exists(inToken) then
                gobjTokens.Item(inToken) = array(inType, inData)
            else
                gobjTokens.Add inToken, array(inType, inData)
            end if
        end if
    end sub
    '---
    public sub DelToken(inToken)
        if len(inToken) > 0 then
            if gobjTokens.Exists(inToken) then
                gobjTokens.Remove(inToken)
            end if
        end if
    end sub
    '---
    public sub RemoveAllTokens
        gobjTokens.RemoveAll
    end sub
    '---
    public sub parseTemplateFile
        parseFile(gstrTemplateFile)
    end sub
    
    public sub parseTemplateString(inString)
        parseString(inString)
    end sub
    '---
    'Functions
    '---
    public function getParsedTemplateFile
        gstrHTML = ""
        gblnReturn = true
        getParsedTemplateFile = parseFile(gstrTemplateFile)
    end function
    '---
    public function getParsedTemplateString(inString)
        gstrHTML = ""
        gblnReturn = true
        getParsedTemplateString = parseString(inString)
    end function
    '---
    private function parseString(inString)
        dim astrData
        if len(inString) > 0 then
            astrData = split(inString & vbCrLf, VbCrLf)
            call parseArray(astrData)
        end if
        if gblnReturn then parseString = gstrHTML
    end function
    '---
    private function parseFile(inFile)
        if len(inFile) > 0 then
            if fileExists(inFile) then
                call parseArray(loadFile(inFile, 10))
            end if
        end if
        if gblnReturn then parseFile = gstrHTML
    end function
    '---
    private sub parseArray(inArray)
        dim strLine
        for each strLine in inArray
            call parseLine(strLine & VbCrLf)
        next
    end sub
    '---
    private sub parseLine(inLine)
        dim intA, intB, strLine, strLine2, strToken
        intA = instr(inLine, gstrOpenTag)
        if intA > 0 then
            strLine = left(inLine, intA - 1)
            intB = instr(inLine, gstrCloseTag)
            strLine2 = mid(inLine, intB + len(gstrCloseTag))
            strToken = trim(mid(inLine, intA + len(gstrOpenTag), (intB - intA - len(gstrOpenTag))))
            call printLine(strLine)
            call getToken(strToken)
            call parseLine(strLine2)
        else
            call printLine(inLine)
        end if
    end sub
    '---
    private sub getToken(inToken)
        if gobjTokens.Exists(inToken) then
            dim intTokenType, strTokenData
            intTokenType = gobjTokens.Item(inToken)(0)
            strTokenData = gobjTokens.Item(inToken)(1)
            select case intTokenType
                case 1  'Display Variable
                    call printLine(strTokenData)
                case 2  'Load File, Parse & Display
                    call parseArray(loadFile(strTokenData, 10))
                case 3  'Load File & Display
                    call printLine(loadFile(strTokenData, 1))
                case 5  'Parse String
                    call parseLine(strTokenData)
                case 6  'Parse Array
                    call parseArray(strTokenData)
            end select
        end if
    end sub
    '---
    public function fileExists(inFile)
        dim objFSO
        set objFSO = createobject("Scripting.FileSystemObject")
        if objFSO.FileExists(Server.Mappath(inFile)) then FileExists = True
        set objFSO = nothing
    end function
    '---
    public function loadFile(inFileName, inType)
        dim objFSO, objFile, objStream, strText
        if fileExists(inFileName) then
            set objFSO = createobject("Scripting.FileSystemObject")
            set objFile = objFSO.GetFile(Server.Mappath(inFileName))
            set objFSO = nothing
            set objStream = objFile.OpenAsTextStream(1,0)
            strText = objStream.Read(objFile.Size)
            set objStream = nothing
            set objFile = nothing
            select case cint(inType)
                case 0  'Load & Display
                    printLine(strText)
                case 1  'Load & Return
                    loadFile = strText
                case 10 'Load & Return As Array
                    loadFile = split(strText & VbCrLf, VbCrLf)
            end select
        end if
    end function
    '---
    private function printLine(inLine)
        if gblnReturn then
            gstrHTML = gstrHTML & inLine
        else
            response.write(inLine)
        end if
    end function
end class
%>


4. de output
HTML:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
hier worden de weblog posts uit de dbase gehaald
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>Fluffy Convicts Weblog : title</title>
     <style type="text/css">
  body {
    margin-top: 20px;
    margin-left: 20px;
    margin-right: 20px;
    margin-bottom: 20px;
    }
  body, td, p {
    font-family: verdana, sans-serif;
    font-size: 12px;
    }
  a {
    text-decoration: none;
    }
  a:hover {
    text-decoration:underline;
    }
  .newstext, .nav {
    line-height: 18px;
    }
 /* calendar stuff: */
     .today
    {
    FONT-SIZE: 9px;
    COLOR: #aa0000;
    FONT-FAMILY: verdana,arial,helvetica;
    }
    .weekday
    {
    FONT-SIZE: 9px;
    COLOR: #00aa00;
    FONT-FAMILY: verdana,arial,helvetica;
    }
    .weekend
    {
    FONT-SIZE: 9px;
    COLOR: #0000aa;
    FONT-FAMILY: verdana,arial,helvetica;
    }
    .heading
    {
    FONT-SIZE: 10px;
    COLOR: #0000aa;
    FONT-FAMILY: verdana,arial,helvetica;
    }
    .subheading
    {
    FONT-SIZE: 10px;
    COLOR: #000000;
    FONT-FAMILY: verdana,arial,helvetica;
    }
</style>  
  </head>
<body>
<table width="780" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr> 
    <td width="28">[img]"img/top1.gif"[/img]</td>
    <td width="722">
      <table width="722" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="11">[img]"img/topBG.gif"[/img]</td>
          <td width="711" valign="top" background="img/topBG.gif"> 
            <p>[img]""[/img]<br><b><font size="+2">Fluffy Convicts Weblog</font></b>
            <i>The journey is the reward</i></p>
          </td>
        </tr>
      </table>
    </td>
    <td width="30">[img]"img/top3.gif"[/img]</td>
  </tr>
  <tr> 
    <td width="28" background="img/leftBG.gif" valign="top"><img src="img/leftBG.gif" 
width="28" height="20" alt="-"></td>
    <td width="722" bgcolor="#FFFFFF"> 
      <table width="722" border="0" cellspacing="0" cellpadding="0" align="center">
        <tr> 
          <td width="120" valign="top"> 
            <table width="120" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td colspan="3" height="10">[img]""[/img]</td>
              </tr>
              <tr> 
                <td width="10">[img]""[/img]</td>
                <td> 
                  <p><b><font size="-2">Navigation<br>
                  </font></b><font size="-2">link1<br>link2<br>link3</font></p>
                </td>
                <td width="10">[img]""[/img]</td>
              </tr>
              <tr>
                <td colspan="3" height="10">[img]""[/img]</td>
              </tr>
            </table>
          </td>
          <td valign="top" width="100%"> 
            <table width="100%" border="0" cellspacing="0" cellpadding="11">
              <tr> 
                <td><p></p></td>
              </tr>
            </table>
          </td>
          <td width="160" valign="top"> 
            <table width="160" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td colspan="3" height="10">[img]""[/img]</td>
              </tr>
              <tr> 
                <td width="10">[img]""[/img]</td>
                <td> 
                  <p>hier komt later een kalender</p>
                </td>
                <td width="10">[img]""[/img]</td>
              </tr>
              <tr>
                <td colspan="3" height="10">[img]""[/img]</td>
              </tr>
            </table>
          </td>       
        </tr>
      </table>
    </td>
    <td width="12" align="right" valign="top" background="img/rightBG.gif">
[img]"img/rightBG.gif"[/img]</td>
  </tr>
  <tr> 
    <td>[img]"img/bottom1.gif"[/img]</td>
    <td background="img/bottomBG.gif">[img]"img/bottomBG.gif"[/img]</td>
    <td>[img]"img/bottom3.gif"[/img]</td>
  </tr>
</table>
<p align="center"> <font size="-2">Last update: 10/15/2002 3:21:54 PM<br>
  Copyright 2002 Fluffy Convicts Weblog </font></p>
<p align="center">"this is a reveller site"
</body>
</html>


Als je eea zou willen testen: copy-paste de code van pagina 1, 2 en 3. Stop ze in dezelfde webfolder en run http://localhost/zelfdewebfolder/lemonlime.asp. Uiteraard heb jij lekker geen plaatjes :p

"Real software engineers work from 9 to 5, because that is the way the job is described in the formal spec. Working late would feel like using an undocumented external procedure."


  • Kama
  • Registratie: Mei 2002
  • Laatst online: 28-08 11:43

Kama

Aritifical Intelligenticus

Maak er een Sub van ipv een Function.

Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
sub showPosts
    sql="select top 3 * from tblWebLog order by dtmDateStamp desc" 
    makeRS(SQL)

    sHTML = ""
    do while not rs.EOF
        strLabel=rs("strLabel")
        strText=rs("strText")
        sHTML = sHTML & "<table border=0 width=90>"
        sHTML = sHTML & "<tr><td bgcolor='#DDDDDD'>"
        sHTML = sHTML & strLabel
        sHTML = sHTML & "</td></tr><tr><td>"
        sHTML = sHTML & strText
        sHTML = sHTML & "</td></tr></table>"
        rs.movenext
    loop
    rs.close
    Response.Write(sHTML)
end sub


Twee aanpassingen: Ten eerste moet er (Zoals al gezegd) een </td></tr> bij en ten tweede zag ik dat je in de do lus een sHtml="" in had zitten die er wellicht niet in thuishoorde. Anders laat je nl alsnog alleen de laatste record zien ;-)

Ik gebruik overigens zelf altijd <%=sHtml%> (of hier dus: %><%=sHtml%><% )

Suc6

[ Voor 0% gewijzigd door Kama op 15-10-2002 15:51 . Reden: ff netjes in een codeblokje gezet ]

Niels


Verwijderd

anders kan je misschien wel op een functie laten staan , maar dan ipv de response.write (sHTML) er showPosts = sHTML doen en dan idd zoals Kama zei de %><%=sHtml%><%

  • Crazy D
  • Registratie: Augustus 2000
  • Laatst online: 10:06

Crazy D

I think we should take a look.

Oef ik had niet verwacht dat het zoveel code zou zijn :P Maar ja het probleem is simpel: .AddToken "bodyText", 1, showPosts()
Je wilt als waarde het resultaat van de showPosts functie meegeven zodat in je body die tekst gebruikt kan worden. Alleen, je print in de showPosts functie de waarde, dus, je bent nog aan het stoeien met je template class, en voordat dat ding geparsed wordt (want je bent nog waardes aan het zetten), wordt showPosts aangeroepen. Die spuugt tekst uit, en die gaat naar de browser. Daarna wordt he template geparsed, et voila, je hebt een probleem :)
Oplossing:
functie ook als functie laten werken ;) en strHtml teruggeven ipv uitspugen
code:
1
2
3
4
5
Function showPosts()
    Dim sHTML
    sHTML = "Hier vullen en doen wat je er mee wilt doen"
    showPosts = sHTML
End Function


Overigens is
<%=variabele (of functie die een waarde teruggeeft%>
gewoon een wrapper voor
Response.Write
Als je "midden in" een lap asp code ff tekst wilt printen, doe je dat met Response.Write var. Om dan eerst de asp code af te sluiten met %> vervolgens <%=var%> om de tekst te printen, en dan weer de asp tag openen met <% maakt het er niet sneller op, en is nogal overbodig. En per saldo maakt het voor het eindresultaat niet uit, aangezien het allebei hetzelfde doet: de inhoud van var wordt naar de client gespuugt.
<%=var%> is eigenlijk (imho dan) alleen handig als je midden in een berg html code ff een variabele wilt uitspugen (<html><head zooi><body><h1><%=titel%></h1> etc)

Exact expert nodig?


  • Reveller
  • Registratie: Augustus 2002
  • Laatst online: 05-12-2022
Heren, de aangedragen oplossingen werken niet. Het probleem zit hem ook niet in de gegevens uit de dbase halen (zaten trouwens idd 2 foutjes in de loop ;)) maar in de Response.Write die niet werkt zoals ik wil. Overigens heeft <%= x %> dezelfde werking als Response.Write(x), dus da's ook geen oplossing. De %>ASP onderbreken<% kan ook niet...krijg dan een foutmeling omdat de opbouw van de template onderbroken wordt.

Kijk alsjeblieft eens naar mijn derde post in dit topic - daar staat het probleem, zonder dbase gedoe, nog eens uiteen gezet. Ik ben al zo lang met dit probleem bezig; ik hoop dat iemand een oplossing kan aandragen.

"Real software engineers work from 9 to 5, because that is the way the job is described in the formal spec. Working late would feel like using an undocumented external procedure."


  • Reveller
  • Registratie: Augustus 2002
  • Laatst online: 05-12-2022
niet reageren op mijn vorige post! Crazy_D heeft zojuist de oplossing aangedragen

Crazy_D: _/-\o_ _/-\o_ _/-\o_ _/-\o_ _/-\o_ _/-\o_ _/-\o_ _/-\o_ _/-\o_

"functie ook als functie laten werken" - ik weet het: moet een heeeeeeeeeeleboel aan mijn vbscript capaciteiten werken ;) Enorm bedankt!!! Ook de anderen die hun tijd en aandacht in dit topic gestoken hebben natuurlijk :)

"Real software engineers work from 9 to 5, because that is the way the job is described in the formal spec. Working late would feel like using an undocumented external procedure."


  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06-2025

drm

f0pc0dert

Volgende keer ff het Afbeeldingslocatie: http://images.tweakers.net/forum/templates/got/images/icons/edit.gif knopje gebruiken, daar istie voor.

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz


  • DukeMan
  • Registratie: Mei 2000
  • Niet online
Het moet ook als sub te doen zijn...
ligt het niet aan de volgende regel??
Reveller schreef op 15 oktober 2002 @ 14:14:
situatie

(code)
sHTML = sHTML & strLabel
sHTML = sHTML & "</td></tr>"
sHTML = sHTML & "<tr><td>"
sHTML = sHTML & strText
(/code)
je sluit je tabellen niet goed af, en daardoor plaats ie het boven aan je pagina.

(ik heb de [ code ] tags niet gebruikt, aangezien ik daar de vette regel niet in wist aan te geven....
Pagina: 1