Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export to File 1

Status
Not open for further replies.

Reynet01

Technical User
Apr 27, 2004
59
US
I have a response.write statement on my page that writes out a license code string which looks like this

[RTAuth]
XXXXXXX=RTVoiceLines=0120-XXXXXXXXXX

Here is the code
<%response.Write"[RTAuth]"+"<BR>"+((Recordset1.Fields.Item("LicenseCode").Value)+"=RTVoiceLines="+(Recordset1.Fields.Item("Ports").Value)+"-"+(Recordset1.Fields.Item("actcode").Value))%>

I would like to know if their is way to export this license string to a file where the user can click a link and download the license file the name of the file would be vblicense.ini "it is nothing but a text file with the license string in it" Thanks for any help

If knowledge were power I would be a AAA battery!
 
your code is fine...no need to post it so many times...

make your asp page just to have...

Code:
<%
filename="vblicense.txt"
response.contenttype="text/plain"

Response.AddHeader "content-disposition", "attachment; filename=""" & fileName & """"
dim myvar
myvar=request.querystring("licensenumber")
response.write myvar
%>

just these 7 lines no other headers or anything...

-DNG
 
Ok thats done but I still get a error
Line:64
Error:Expected ')'

Line 64 is with the the code

<td><a href= "#" ONCLICK = 'downloadfile( <%="[RTAuth]"+"<BR>"+((Recordset1.Fields.Item("LicenseCode").Value)+"=RTVoiceLines="+(Recordset1.Fields.Item("Ports").Value)+"-"+(Recordset1.Fields.Item("actcode").Value))%>)'><%="[RTAuth]"+"<BR>"+((Recordset1.Fields.Item("LicenseCode").Value)+"=RTVoiceLines="+(Recordset1.Fields.Item("Ports").Value)+"-"+(Recordset1.Fields.Item("actcode").Value))%>licensenumber</a></td>

If knowledge were power I would be a AAA battery!
 
it also says undetermined string variable

which is licensenumber

If knowledge were power I would be a AAA battery!
 
oh ok...one small change...

Code:
<td><a href= "#" ONCLICK = 'downloadfile([red][b]"[/b][/red]<%="[RTAuth]"+"<BR>"+((Recordset1.Fields.Item("LicenseCode").Value)+"=RTVoiceLines="+(Recordset1.Fields.Item("Ports").Value)+"-"+(Recordset1.Fields.Item("actcode").Value))%>[red][b]"[/b][/red])'><%="[RTAuth]"+"<BR>"+((Recordset1.Fields.Item("LicenseCode").Value)+"=RTVoiceLines="+(Recordset1.Fields.Item("Ports").Value)+"-"+(Recordset1.Fields.Item("actcode").Value))%>licensenumber</a></td>

that double quotes should solve all the problems...

-DNG
 
The double quotes fixed the Expected Error but the undetermind string constant is still there

If knowledge were power I would be a AAA battery!
 
one more mistake you did:

Code:
<td><a href= "#" ONCLICK = 'downloadfile("<%="[RTAuth]"+"<BR>"+((Recordset1.Fields.Item("LicenseCode").Value)+"=RTVoiceLines="+(Recordset1.Fields.Item("Ports").Value)+"-"+(Recordset1.Fields.Item("actcode").Value))%>")'><%="[RTAuth]"+"<BR>"+((Recordset1.Fields.Item("LicenseCode").Value)+"=RTVoiceLines="+(Recordset1.Fields.Item("Ports").Value)+"-"+(Recordset1.Fields.Item("actcode").Value))%>[s][red]licensenumber[/red][/s]</a></td>

remove that...

-DNG
 
Ok I just took that out but it still says licensenumber has not been defined

If knowledge were power I would be a AAA battery!
 
then just dim the variable somewhere in the code...

Dim licensenumber

-DNG
 
I keep getting the same error here is my dim statement

dim licensenumber
licensenumber= <% response.write "[RTAuth]"+"<BR>"+ ((Recordset1.Fields.Item("LicenseCode").Value)+ "=RTVoiceLines="+ (Recordset1.Fields.Item("Ports").Value)+"-"+(Recordset1.Fields.Item("actcode").Value))%>

If knowledge were power I would be a AAA battery!
 
post your complete example.asp page...the error is because of some typos...i saw your page is running fine...expect that the sub routine is not getting called correctly...make sure you have no typos...post the complete code for example.asp

-DNG
 
here is the full code

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/RS1.asp" -->
<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert")) = "form1") Then

MM_editConnection = MM_RS1_STRING
MM_editTable = "dbo.Pronexus"
MM_editRedirectUrl = "pronexus.asp"
MM_fieldsStr = "txtcompany|value|txtlicensecode|value|txtports|value|txtdate|value|txtactcode|value"
MM_columnsStr = "Company|',none,''|LicenseCode|',none,''|Ports|',none,''|DateofIssue|',none,NULL|actcode|',none,''"

' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")

' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues

If (CStr(Request("MM_insert")) <> "") Then

' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%>
<%
Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_RS1_STRING
Recordset1.Source = "SELECT * FROM dbo.Pronexus"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>

<html>
<%dim licensenumber%>
<title>VB Licenses</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<div align="Left">
<p align="center"><font size="5"> License Management</font></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<form name="form1" method="POST" action="<%=MM_editAction%>">
<table width="100%" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="39%"><div align="center"><strong>Company</strong></div></td>
<td width="19%"><div align="center"><strong>License Code</strong></div></td>
<td width="20%"><div align="center"><strong>Number of Ports</strong></div></td>
<td width="22%"><div align="center"><strong>ActCode</strong></div></td>
<td width="22%"><div align="center"><strong>Date of Issue</strong></div></td>
</tr>
<tr>
<td><div align="center">
<input name="txtcompany" type="text" id="txtcompany" size="30" maxlength="50">
</div></td>
<td><div align="center">
<input name="txtlicensecode" type="text" id="txtlicensecode">
</div></td>
<td><div align="center">
<input name="txtports" type="text" id="txtports">
</div></td>
<td><div align="center">
<input name="txtactcode" type="text" id="txtactcode2">
</div></td>
<td><div align="center">
<input name="txtdate" type="text" id="txtdate4">
</div></td>
</tr>
<tr>
<td><div align="center"></div></td>
<td><div align="center"></div></td>
<td><div align="center"></div></td>
<td> <div align="center"></div></td>
<td><div align="center">
<input type="submit" name="Submit" value="Enter New Record">
</div></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
Test page enter any info
</form>
<p>&nbsp;</p>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="31%"><div align="center">Company</div></td>
<td width="14%"><div align="center">Ports</div></td>
<td width="14%"><div align="center">Date of Issue</div></td>
<td width="41%"><div align="center">License String</div></td>
</tr>
<%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%>
<tr>
<td><%=(Recordset1.Fields.Item("Company").Value)%></td>
<td><%=(Recordset1.Fields.Item("Ports").Value)%></td>
<td><%=(Recordset1.Fields.Item("DateofIssue").Value)%></td>
<td><a href= "#" ONCLICK = 'downloadfile("<%="[RTAuth]"+"<BR>"+((Recordset1.Fields.Item("LicenseCode").Value)+"=RTVoiceLines="+(Recordset1.Fields.Item("Ports").Value)+"-"+(Recordset1.Fields.Item("actcode").Value))%>")'><%="[RTAuth]"+"<BR>"+((Recordset1.Fields.Item("LicenseCode").Value)+"=RTVoiceLines="+(Recordset1.Fields.Item("Ports").Value)+"-"+(Recordset1.Fields.Item("actcode").Value))%></a></td>


</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p align="left">&nbsp;</p>
</div>


<script language="VBscript">
Sub downloadfile(licensenumber)
Window.Open "mypage.asp?licensenumber='"&licensenumber&"'
End Sub
</script>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>


If knowledge were power I would be a AAA battery!
 
ok lets make some changes...changes in red
Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/RS1.asp" -->
<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert")) = "form1") Then

  MM_editConnection = MM_RS1_STRING
  MM_editTable = "dbo.Pronexus"
  MM_editRedirectUrl = "pronexus.asp"
  MM_fieldsStr  = "txtcompany|value|txtlicensecode|value|txtports|value|txtdate|value|txtactcode|value"
  MM_columnsStr = "Company|',none,''|LicenseCode|',none,''|Ports|',none,''|DateofIssue|',none,NULL|actcode|',none,''"

  ' create the MM_fields and MM_columns arrays
  MM_fields = Split(MM_fieldsStr, "|")
  MM_columns = Split(MM_columnsStr, "|")
  
  ' set the form values
  For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
  Next

  ' append the query string to the redirect URL
  If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
    If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
      MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
    Else
      MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
    End If
  End If

End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues

If (CStr(Request("MM_insert")) <> "") Then

  ' create the sql insert statement
  MM_tableValues = ""
  MM_dbValues = ""
  For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_formVal = MM_fields(MM_i+1)
    MM_typeArray = Split(MM_columns(MM_i+1),",")
    MM_delim = MM_typeArray(0)
    If (MM_delim = "none") Then MM_delim = ""
    MM_altVal = MM_typeArray(1)
    If (MM_altVal = "none") Then MM_altVal = ""
    MM_emptyVal = MM_typeArray(2)
    If (MM_emptyVal = "none") Then MM_emptyVal = ""
    If (MM_formVal = "") Then
      MM_formVal = MM_emptyVal
    Else
      If (MM_altVal <> "") Then
        MM_formVal = MM_altVal
      ElseIf (MM_delim = "'") Then  ' escape quotes
        MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
      Else
        MM_formVal = MM_delim + MM_formVal + MM_delim
      End If
    End If
    If (MM_i <> LBound(MM_fields)) Then
      MM_tableValues = MM_tableValues & ","
      MM_dbValues = MM_dbValues & ","
    End If
    MM_tableValues = MM_tableValues & MM_columns(MM_i)
    MM_dbValues = MM_dbValues & MM_formVal
  Next
  MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

  If (Not MM_abortEdit) Then
    ' execute the insert
    Set MM_editCmd = Server.CreateObject("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

    If (MM_editRedirectUrl <> "") Then
      Response.Redirect(MM_editRedirectUrl)
    End If
  End If

End If
%>
<%
Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_RS1_STRING
Recordset1.Source = "SELECT *  FROM dbo.Pronexus"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>

<html>
<%dim licensenumber%>
<title>VB Licenses</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<div align="Left">
  <p align="center"><font size="5"> License Management</font></p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <form name="form1" method="POST" action="<%=MM_editAction%>">
    <table width="100%" border="1" align="center" cellpadding="0" cellspacing="0">
      <tr> 
        <td width="39%"><div align="center"><strong>Company</strong></div></td>
        <td width="19%"><div align="center"><strong>License Code</strong></div></td>
        <td width="20%"><div align="center"><strong>Number of Ports</strong></div></td>
        <td width="22%"><div align="center"><strong>ActCode</strong></div></td>
        <td width="22%"><div align="center"><strong>Date of Issue</strong></div></td>
      </tr>
      <tr> 
        <td><div align="center"> 
            <input name="txtcompany" type="text" id="txtcompany" size="30" maxlength="50">
          </div></td>
        <td><div align="center"> 
            <input name="txtlicensecode" type="text" id="txtlicensecode">
          </div></td>
        <td><div align="center"> 
            <input name="txtports" type="text" id="txtports">
          </div></td>
        <td><div align="center"> 
            <input name="txtactcode" type="text" id="txtactcode2">
          </div></td>
        <td><div align="center"> 
            <input name="txtdate" type="text" id="txtdate4">
          </div></td>
      </tr>
      <tr> 
        <td><div align="center"></div></td>
        <td><div align="center"></div></td>
        <td><div align="center"></div></td>
        <td> <div align="center"></div></td>
        <td><div align="center"> 
            <input type="submit" name="Submit" value="Enter New Record">
          </div></td>
      </tr>
    </table>
    <input type="hidden" name="MM_insert" value="form1">
    Test page enter any info 
  </form>
  <p>&nbsp;</p>
  <table width="100%" border="1" cellspacing="0" cellpadding="0">
    <tr> 
      <td width="31%"><div align="center">Company</div></td>
      <td width="14%"><div align="center">Ports</div></td>
      <td width="14%"><div align="center">Date of Issue</div></td>
      <td width="41%"><div align="center">License String</div></td>
    </tr>
    <% 
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF)) 
%>
    <tr> 
      <td><%=(Recordset1.Fields.Item("Company").Value)%></td>
      <td><%=(Recordset1.Fields.Item("Ports").Value)%></td>
      <td><%=(Recordset1.Fields.Item("DateofIssue").Value)%></td>
<td><a href= "#" ONCLICK = 'downloadfile("<%="[RTAuth]"+"<BR>"+((Recordset1.Fields.Item("LicenseCode").Value)+"=RTVoiceLines="+(Recordset1.Fields.Item("Ports").Value)+"-"+(Recordset1.Fields.Item("actcode").Value))%>")'><%="[RTAuth]"+"<BR>"+((Recordset1.Fields.Item("LicenseCode").Value)+"=RTVoiceLines="+(Recordset1.Fields.Item("Ports").Value)+"-"+(Recordset1.Fields.Item("actcode").Value))%></a></td>


   </tr>
    <% 
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  Recordset1.MoveNext()
Wend
%>
  </table>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p align="left">&nbsp;</p>
</div>


[red]<script>[/red]
Sub downloadfile(licensenumber)
Window.Open "mypage.asp?[red]mylicensestring="[/red]&licensenumber
End Sub
</script>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>

and your mypage.asp should be like this:

Code:
<%
filename="vblicense.ini"
response.contenttype="text/plain"

Response.AddHeader "content-disposition", "attachment; filename=""" & fileName & """"
dim myvar
myvar=request.querystring("[red]mylicensestring[/red]")
response.write myvar
%>

-DNG
 
error at line 132
Error expected ';'


Debugger shows it at

<script>
Sub downloadfile(licensenumber)
Window.Open "mypage.asp?mylicensestring="&licensenumber
End Sub
</script>

If knowledge were power I would be a AAA battery!
 
how about putting a semicolon in the second line..try this:

<script>
Sub downloadfile(licensenumber)
Window.Open "mypage.asp?mylicensestring="&licensenumber;
End Sub
</script>

-DNG
 
ok i dont think semicolon is the problem...

try this...

change 1. remove this line from the top of your example.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>


change 2.

<script language="vbscript">
Sub downloadfile(licensenumber)
Window.Open "mypage.asp?mylicensestring="&licensenumber
End Sub
</script>

-DNG
 
also do this test case...not related with your previous code...

JUST A DIFFERENT TEST CASE....

just paste this code into new asp file, just these 7 lines...no other code...name the file as
mytest.asp

Code:
<%
filename="vblicense.ini"
response.contenttype="text/plain"

Response.AddHeader "content-disposition", "attachment; filename=""" & fileName & """"
dim myvar
myvar=myvar="[RTAuth]3UA5ZCY=RTVoiceLines=0002-4A6QZCERE0"
response.write myvar
%>

now open browser and go to this link


let me know if the page works fine...prompting you to
download the file and when you download and open the file
you see the license.

-DNG
 
Bingo! only one small problem I need the license file to read like this

[RTAuth]
kfkfkfk=RTVoiceLines=0048-dddddddddd[Color]


it is putting the text out like this

[RTAuth]<BR>kfkfkfk=RTVoiceLines=0048-dddddddddd

how can I get it to add a return after [RTAuth]


If knowledge were power I would be a AAA battery!
 
disregaurd the Tag

If knowledge were power I would be a AAA battery!
 
ok great...yes i saw the link...its working..congrats...
just make this change in mypage.asp and you are good to go...
Code:
<%
filename="vblicense.ini"
response.contenttype="text/plain"

Response.AddHeader "content-disposition", "attachment; filename=""" & fileName & """"
dim myvar
myvar=request.querystring("mylicensestring")
[red]myvar=replace(myvar,"<BR>","")[/red]
response.write myvar
%>

-DNG
 
thanks that took the <BR> out but can I get it to put a carriage return after the [RTAuth}

If knowledge were power I would be a AAA battery!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top