0

I'm teaching myself VBS and I decided to write a message encryption program. It uses the left and right functions in a loop to read every individual character.

DO 
wscript.sleep 100
if Az=0 then
EXIT DO
end if
CR=right(message,aZ)
DEL=left(CR,1)
aZ=aZ-1
zZ=zZ+1
supra=""
supra="supra"
CALL KEYCOUNT
CD=left(keyword,zZ)
TAC=right(CD,1)
....

From there, it sets every character equal to a different letter based on an encryption keyword and moves onto the next character. My problem is I don't know how to deal with spaces in the message. Is there a way to make a variable have the value of a space? I've tried:

set var=space(1)
set var="&"" ""&"
set var=""
set var=" "
set var=""" """

I'm certain there are things I'm not thinking of

Thanks

Joseph

QProgram
  • 51
  • 2
  • 7

2 Answers2

0

The problem is that you use Set (cf. here) when assigning a simple/non-object value to a variable. If you loose it, your experimental statements will 'work' (compile & run without error). Look at the output and you'll see that

var = " "

is the correct and most efficient way to assign a (string containing one) space to a variable.

Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
0

set statement assigns an object reference to a variable or property, or associates a procedure reference with an event. That isn't our case.

var=space(1)  ' var contains one space character
var="&"" ""&" ' var contains &" "&
var=""        ' var contains a string of zero length
var=" "       ' var contains one space character
var=""" """   ' var contains " "

Or, if you would like, declare a constant for use in place of literal value of space (anywhere in your script) as follows:

Const vbSp=" "

Constants are public by default. Within procedures, constants are always private; their visibility can't be changed. Within a script, the default visibility of a script-level constant can be changed using the Private keyword. There are variations:

Private Const vbSp=" "
Public  Const vbSp=" "
JosefZ
  • 28,460
  • 5
  • 44
  • 83