Page 2 of 2

Re: How to get a doubleQuote into a string ?

Posted: Sat Feb 07, 2015 11:50 pm
by vmars316
skywalk wrote:

Code: Select all

#DQ$            = Chr(34)
MyString$ = #DQ$ + "Hello" + #DQ$
debug MyString$
Pls, What is the diff between #DQ$ and DQ$ ? Thanks

Re: How to get a doubleQuote into a string ?

Posted: Sat Feb 07, 2015 11:52 pm
by vmars316
StarBootics wrote:Another way around :

Code: Select all

MyString$ = Chr(34) + "Hello" + Chr(34)
Debug MyString$
Oh, ya, Thanks

Re: How to get a doubleQuote into a string ?

Posted: Sat Feb 07, 2015 11:57 pm
by vmars316
idle wrote:wrapping it in a macro is perhaps more convenient

Code: Select all

Macro DQ(text) 
  #DQUOTE$ + text + #DQUOTE$ 
EndMacro   

mystring.s = DQ("foo") + "," + DQ("bar") 

Debug mystring
Ah, What fun! I have downloaded this whole page.
Thanks All..

Re: How to get a doubleQuote into a string ?

Posted: Sun Feb 08, 2015 12:06 am
by vmars316
And now for the other shoe:

Outputting Html-code from a PB program.
I am still having trouble writing DoubleQuotes into Html code.

Input file looks like this:

0,0,E6E9FE
1,0,E7EAFF
2,0,E7EBFE
3,0,E8ECFF

Variables:
DQ$ = Chr(34)
TBox02dot$ contains E6E9FE (after 1st record is read in.)
OneLine$ contains 0,0,E6E9FE (after 1st record is read in.)

The line of code that transforms the above variables into
<TR><TD style=height:50px; background-color:#E6E9FE;>0,0,E6E9FE</TD>

is this code:
LTTD01$ = "<TR><TD style="+DQ$+"height:50px; background-color:#"+TBox02dot$+";"+DQ$+">"+OneLine$+"</TD>"

But that isn't what I want.
I want the code above to transform the input file into this:
<TR><TD style="height:50px; background-color:#E6E9FE;">0,0,E6E9FE</TD>
See the doubleQuotes!
But the html that gets generated is this:

<!DOCTYPE HTML PUBLIC-//W3C//DTD HTML 4.01 Transitional//EN >
<html><head>
<meta charset=utf-8><title>xRainbow-Project</title>
<style>
table td {border: 1px solid black; color: Black;}</style>
</head><body>
<TABLE>
<TR><TD style=height:50px; background-color:#E6E9FE;>0,0,E6E9FE</TD>
<TR><TD style=height:50px; background-color:#E7EAFF;>1,0,E7EAFF</TD>
<TR><TD style=height:50px; background-color:#E7EBFE;>2,0,E7EBFE</TD>
<TR><TD style=height:50px; background-color:#E8ECFF;>3,0,E8ECFF</TD>
</TABLE></body></html>

ie., No doubleQuotes.


Here is the whole program code:

Code: Select all

;From: OpenFile_Example.pb , Author: wayne1 (updated for PB4.00 by blbltheworm)
;input data generated fron ProgramName: xRainbow-vera.pb 
Define.s OneLines = "Z00,000,FAE0D9"  
Define.s TBox02$  , DQ$ = Chr(34) 
Define.i OneLinei , x , y , CommaCnt , CountLinesOut
Global FileOpen = 0 , OneLine$="" , OneLiner$="" , OneLineByte$=""  
Global TableBeg$ = "<TABLE>"
Global LTTD01$,LTTD02$,QTGT01$,TD02$,TD01$,TBox02dot$  

;Structure TableRow
;     TRbeg.s = "<TR>"
;  TDbeg01a.s = "<TD style=  + DQ$ +  color:black  + DQ$ +  "
;    TBox01.s = "000,000,FFFFFF"
;  TDbeg01b.s = ">"
;  TDbeg02a.s = "<TD BGCOLOR =   + DQ$ +  #"
;    TBox02.s ; = "FFFFFF"
;  TDbeg02b.s = ">"
;     TDend.s = "</TD>"
;     TRend.s = "</TR>"
;EndStructure
     
Procedure LoadHexColor(OneLine$)     
OneLinei = StringByteLength(OneLine$, #PB_Ascii)
CommaCnt = 0  : TBox02$ = "" 
For x = 1 To OneLinei 
  OneLineByte$ = Mid(OneLine$, x, 1)
    If OneLineByte$ = ","   
      CommaCnt = CommaCnt +1  
    EndIf 
    
    If OneLineByte$ <> ","
        If CommaCnt > 1 
          TBox02$ = TBox02$ + OneLineByte$ 
        EndIf 
    EndIf    
Next 
TBox02.s = TBox02$  ; loadup TableRow.TBox02.s 
TBox02dot$ = TBox02$
EndProcedure  ; LoadHexColor()  
  
Procedure FileOut(OneLine$)
     If FileOpen = 0 
      If CreateFile(2, "ColorTable.html") 
          FileOpen = 1
          WriteStringN(2,"<!DOCTYPE HTML PUBLIC"  + DQ$ + "-//W3C//DTD HTML 4.01 Transitional//EN " + DQ$ + ">")
          WriteStringN(2,"<html><head>")
          WriteStringN(2,"<meta charset=" + DQ$ + "utf-8" + DQ$ + "><title>xRainbow-Project</title>")
          WriteStringN(2,"<style>")
          WriteStringN(2,"table td {border: 1px solid black; color: Black;}</style>")
          WriteStringN(2,"</head><body>")   
          WriteStringN(2,TableBeg$)
      Else       
         MessageRequester("PureBasic", "Error: can't Create file", 0) 
        End  
      EndIf  ; CreateFile(2,
        
    EndIf  ; FileOpen = 0  
  LoadHexColor(OneLine$)
    
LTTD01$ = "<TR><TD style="+DQ$+"height:50px; background-color:#"+TBox02dot$+";"+DQ$+">"+OneLine$+"</TD>"
TD01$ = LTTD01$ + TBox01.s ;+ "</TD>"
WriteStringN(2, TD01$)
  OneLine$ = ""
EndProcedure ;FileOut(OneLine$)   
    
  Procedure OFile(file.s) 
   d=ReadFile(1, file) 
    If d 
      While Eof(1)=0 
        Text$ = ReadString(1)  ; +Chr(13)+ Chr(10) 
        OneLine$ = Text$  ; "testing line"+"<br>" ; TableRow
        TBox01.s = OneLine$
        CountLinesOut+1
        FileOut(OneLine$)
        If CountLinesOut > 3
          Break 
        EndIf  
      Wend 
      CloseFile(1) 
      WriteStringN(2,"</TABLE></body></html>")
      CloseFile(2)
      SetGadgetText(2, Text$) 
      Else 
      MessageRequester("Error","No valid file was selected.",#MB_ICONERROR) 
    EndIf 
  MessageRequester("#Lines Out =",Str(CountLinesOut)) 
  EndProcedure ;OFile(file.s)

If OpenWindow(0, 100, 200, 495, 260, "Open Small Files Example", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget) 
ButtonGadget(1,210,20,80,25,"Open File") 
StringGadget(2,10,60,480,185,"",#ES_MULTILINE | #ES_AUTOVSCROLL|#WS_VSCROLL|#WS_HSCROLL) 

  Repeat 
    EventID.l = WaitWindowEvent() 
    If EventID = #PB_Event_CloseWindow  
      Quit = 1 
    EndIf 
    If EventID = #PB_Event_Gadget 
      Select EventGadget() 
        Case 1 
          file$ = "xRainbow-Vera-CommaS.txt" 
          OFile(file$) 
      EndSelect 
    EndIf 
  Until Quit = 1 
  
EndIf 

End

Re: How to get a doubleQuote into a string ?

Posted: Sun Feb 08, 2015 12:38 am
by skywalk
vmars316 wrote:Pls, What is the diff between #DQ$ and DQ$ ? Thanks
#DQ$ is a constant I defined to keep a shorter name than the existing #DQUOTE$. DQ$ is a string variable. A variable can be changed, the constant cannot(without trickery in a DataSection).

Re: How to get a doubleQuote into a string ?

Posted: Sun Feb 08, 2015 4:00 am
by vmars316
Aha, when I plugged the #DQ$ in there ,
the doubleQuotes now show up in the html-code
and the TD box is now colored.
Thanks All!..

Re: How to get a doubleQuote into a string ?

Posted: Sun Feb 08, 2015 7:41 am
by TI-994A
vmars316 wrote:I am still having trouble writing DoubleQuotes into Html code.
vmars316 wrote:Aha, when I plugged the #DQ$ in there, the doubleQuotes now show up in the html-code...
Hi vmars316. The DQ$ variable did not work because it was utilised within the FileOut() procedure, but declared outside of that scope. It would work if it is declared as a global variable, or a local variable within the procedure itself; like so:

Code: Select all

Define.s OneLines = "Z00,000,FAE0D9"  
Define.s TBox02$
Global DQ$ = Chr(34)
...
or

Code: Select all

Procedure FileOut(OneLine$)
  Define DQ$ = Chr(34) 
  ...
#DQ$, on the other hand, is a constant, and in PureBasic, constants hold a global scope. That's why it worked.

Further, the [$] suffix is a self-declarative string symbol which does not require an explicit string definition; the same way any undefined variable defaults to an integer.

Code: Select all

a   = 1         ;a is an integer by default
a$  = "Hello"   ;a$ is a string by default
b   = "Hello"   ;raises error [Trying to write a string into a numerical variable]
b.s = "Hello"   ;must be explicitly defined with the string type suffix [.s]
Just some thoughts. :)

Re: How to get a doubleQuote into a string ?

Posted: Sun Feb 08, 2015 1:19 pm
by Vera
Hello Vern,

to me the 'TBox02dot$' stays empty (using the code you send me).
To grab each hex-letter (character) one by one and to add them up again is not really necessary as it can be done like this:

Code: Select all

OneLine$ = "0,0,E6E9FE"

Debug OneLine$
Debug Right(OneLine$, 6)
In your example I've changed the 'html' line as follows, to color the cell-backgrounds too:

Code: Select all

; LTTD01$ = "<TR><TD style="+#DQ$+"height:50px; background-color:#"+TBox02dot$+";"+#DQ$+">"+OneLine$+"</TD>"
LTTD01$ = "<TR><TD style=" + #DQ$ + "height:20px; background-color:#" + Right(OneLine$, 6) + ";" + #DQ$ + ">" + OneLine$ + "</TD>"
have a nice day ~ cheers Vera :)

Re: How to get a doubleQuote into a string ?

Posted: Sun Feb 08, 2015 1:32 pm
by Danilo

Re: How to get a doubleQuote into a string ?

Posted: Sun Feb 08, 2015 2:01 pm
by IdeasVacuum

Re: How to get a doubleQuote into a string ?

Posted: Mon Feb 09, 2015 12:19 am
by vmars316
Hey Folks,
I really appreciate your support,
especially when you show 'why/how' things work,
and show 'alternative ways' of doing things.
Thank you...Vern