Results 1 to 6 of 6

Thread: Creating Dynamic Strings

  1. #1

    Thread Starter
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610

    Creating Dynamic Strings

    I wish to create a dynamic string in my program so that it can not be read in the compiled code. In other words I want to display a msgbox that states "The Sky is Blue" but I do not want the phrase "The Sky is Blue" to be found anywhere in the compiled form of my program.

    What is the best way of doing this?
    Thanks
    This space for rent...

  2. #2
    Addicted Member hamins's Avatar
    Join Date
    Sep 2001
    Posts
    192
    Well, there is a way. I'm not sure if it's the best way. It'll be a lil tedious.

    You can write a string like this : -

    msgbox chr(72) + chr(67) etc etc
    Knowledge is static .... understanding is Dynamic

  3. #3
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    If you want to use ^^^ this method, to easily find out all the Chr codes, just use this:

    VB Code:
    1. Private Sub Form_Load()
    2. Text1.Text = ReturnChars("This is an example in VB")
    3. 'MsgBox Chr(84) & Chr(104) & Chr(105) & Chr(115) & Chr(32) & Chr(105) & Chr(115) & Chr(32) & Chr(97) & Chr(110) & Chr(32) & Chr(101) & Chr(120) & Chr(97) & Chr(109) & Chr(112) & Chr(108) & Chr(101) & Chr(32) & Chr(105) & Chr(110) & Chr(32) & Chr(86) & Chr(66)
    4. End Sub
    5. Function ReturnChars(str As String) As String
    6. For i = 1 To Len(str)
    7.     curpos = Mid(str, i, 1)
    8.     ReturnChars = ReturnChars & "Chr(" & Asc(curpos) & ") & "
    9. Next
    10. ReturnChars = Left(ReturnChars, Len(ReturnChars) - 2) 'Get rid of trailing amphersand
    11. End Function

    Then insert the result into your code...

  4. #4
    PowerPoster Arbiter's Avatar
    Join Date
    Sep 2000
    Location
    Manchester
    Posts
    2,276
    Store the string in a coded format and decode it when you wish to display it.
    Gentile or Jew,
    O you who turn the wheel and look to windward,
    Consider Phlebas, who was once handsome and tall as you...

  5. #5

    Thread Starter
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610

    Brain Freeze...

    I need to assign 72,101,108,108,111,32,77,111,109 to the array mystr. I can use the code below
    Code:
    Dim mystr(8) As Integer
    
    mystr(0)=72
    mystr(1)=101
    mystr(2)=108
    mystr(3)=108
    mystr(4)=111
    mystr(5)=32
    mystr(6)=77
    mystr(7)=111
    mystr(8)=109
    But isn't there a way to initialize the array at design time all on one line? I know I can do this but I just cannot remember how.
    This space for rent...

  6. #6

    Thread Starter
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610

    There has to be a better way...

    This is what I came up with to get a msgbox to read "This program was only meant to be a demo." There must be a better way of doing this than what I am doing now. It just seems like this a lot of work just for one string how would I do multiple strings?

    Is a resource file with a string table better? How secure is that resource file?

    Code:
    Option Explicit
    
    Sub Main()
    
    Dim MyStr() As Variant
    
        MyStr = Array(84, 104, 105, 115, 32, 112, 114, 111, 103, 114, 97, 109, 32, 119, 97, 115, _
                      32, 111, 110, 108, 121, 32, 109, 101, 110, 116, 32, 116, 111, 32, 98, 101, _
                      32, 97, 32, 100, 101, 109, 111, 46)
        Call MsgBox(GetString(MyStr))
    
    End Sub
    
    Public Function GetString(InputString As Variant) As String
    
    Dim i As Integer
        
        For i = LBound(InputString) To UBound(InputString)
            GetString = GetString & Chr(InputString(i))
        Next i
        
    End Function
    Thanks for the help again.
    This space for rent...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width