Results 1 to 25 of 25

Thread: Contents of Txt file into Form

  1. #1

    Thread Starter
    Hyperactive Member jokerfool's Avatar
    Join Date
    Dec 2006
    Location
    Gold Coast, Australia
    Posts
    452

    Contents of Txt file into Form

    I have a text file that contains hundreds of website search engine strings e.g.
    Code:
    https://www.google.com.au/search?
    This information is kept in a text file and the text file is distributed with the application. How can I add the search engines to the form instead?

    I have changed the topic and now added the project.

    You will see the abc.txt file. This file contains a search string, when the program is run the user can enter a search then click search to display result.

    What I want to do is eliminate the abc.txt file and place that contents inside the frmSearch.frm instead.

    If the user wants to search all search strings, I wanted to have an option of ticking a box for all, so when you click the search, its then opens x many sites.

    Thank you

    Search.zip
    Last edited by jokerfool; Feb 1st, 2013 at 07:25 AM.

  2. #2
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Contents of Txt file placed in a BAS file instead

    maybe into a resource file?

  3. #3

    Thread Starter
    Hyperactive Member jokerfool's Avatar
    Join Date
    Dec 2006
    Location
    Gold Coast, Australia
    Posts
    452

    Re: Contents of Txt file placed in a BAS file instead

    I thought a resource file was for images only?

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: Contents of Txt file placed in a BAS file instead

    Not sure what you are trying to do. Are we talking a vba app here, a Vb script or actually VB6

    In VB6 Bas files are used only at design time, once your project is compiled there is nothing like a BAS file in the output. The code in the bas file is compiled and made part of the exe

    You can include a text file as a resource but that would not be a bas file, although you could surely name it with a bas extension but there is no reason to do so

    I thought a resource file was for images only?
    Resource files can contain strings, numbers, files, images. One of the most common uses of a resource file is multilingual support where the language of a label or whatever needs to change to that of the user

  5. #5
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Contents of Txt file placed in a BAS file instead

    anything you want but i would not recommand a big file or else your .exe will be too big

  6. #6
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Contents of Txt file placed in a BAS file instead

    You could do it like your code sample making sure you affix the Form name to the Gov (not sure what this is) and cboSite

    You can do a prerun and print the contents of the file to another file but make then look like VB statements. Open the file manually, copy the contents, then paste the contents to your .BAS file

    You can load a Resource File like Max suggested but then you will need a way to read a line if you need to be selective. Not sure how you want to use this data in your app


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  7. #7
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Contents of Txt file placed in a BAS file instead

    Quote Originally Posted by jokerfool View Post
    I thought a resource file was for images only?
    Nope. It for images, string data, and custom


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  8. #8
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Contents of Txt file placed in a BAS file instead

    load to res file and as soon as your app load liad that res file to an array pretty simple
    once its in your array its easy to play arround with it every array item is a different website Array(0) = first item of txt file

  9. #9
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Contents of Txt file placed in a BAS file instead

    Good thought, Max, as usual


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  10. #10

    Thread Starter
    Hyperactive Member jokerfool's Avatar
    Join Date
    Dec 2006
    Location
    Gold Coast, Australia
    Posts
    452

    Re: Contents of Txt file placed in a BAS file instead

    Okay I have a question about the resource file. I currently have a resource file that contains 10 banners, a random banner is displayed each time the application opens. Is it true that I can only have 1 resource file at a time? Cos I tried to make another and it seems to just replace the last RES file. I am not sure how to add the websites to the res file either, but first step is getting the other issue out the way. Thank you.

  11. #11
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    928

    Re: Contents of Txt file placed in a BAS file instead

    Quote Originally Posted by jokerfool View Post
    I have a text file that contains hundreds of website search engine strings e.g.
    Code:
    https://www.google.com.au/search?
    This information is kept in a text file and the text file is distributed with the application. How can I add the search engines to a BAS file and call apon the BAS file instead?

    Text file:

    Code:
        Gov.Clear
        Dim intFree, X As Integer
        X = 1
        intFree = FreeFile
        Open App.Path & "\abc.txt" For Input As #intFree
            Do Until EOF(intFree)
                Input #intFree, mstrName(X), mstrSite(X), mstrAdd(X)
                X = X + 1
            Loop
        Close
        For X = 1 To UBound(mstrName)
            If mstrName(X) <> "" Then
                Gov.AddItem (Format(X, "00") & " - " & mstrName(X))
            End If
        Next X
        
        cboSite.ListIndex = 0
    I wanted to bundle the text file into the BAS file and load the BAS file with the application.

    Thank you.
    IF I UNDERSTAND, you want to do this in REALTIME, RUNTIME, like to incorporate dynamicaly .BAS module , making your app capable to run remote ONLINE .bas modules ON DEMAND.

    You needs to use the VBScript engine, but WARNING that is soooo insecure....., you will expose all you customers if your webserver gets a HACKED.

    I use somthing similar, like ONLINE INSTALLERs, where an unique installer, INSTALL always TOP CURRENT app version nevermind if the installer is old. For doing that, the installer first DOWNLOAD a hashed file that contain a MD5 certificate for all files to download, so the installer DOWNLOADs only TRUSTED files, if any file is hacked, the installer will reject the file. This kind of security is necessary because webservers are always insecure and shared by your webserver-hoster service.
    Last edited by flyguille; Jan 31st, 2013 at 09:26 AM.

  12. #12
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Contents of Txt file placed in a BAS file instead

    Quote Originally Posted by jokerfool View Post
    Is it true that I can only have 1 resource file at a time? Cos I tried to make another and it seems to just replace the last RES file.
    The manual says:

    Only a single resource file may be edited at a time; a project can contain only a single resource file.
    Quote Originally Posted by jokerfool View Post
    I am not sure how to add the websites to the res file either, ...
    You may embed your text file in the exe by adding it to the String Table or, if you want to save space and your text file is ANSI, by importing it as a custom resource. The following instructions are for the custom resource:

    In the VB Resource Editor window (Add-Ins >> Add-In Manager >> VB 6 Resource Editor), click the toolbar button that has the tooltip "Add Custom Resource...". Select your text file from the dialog that shows up. It would probably appear in your resource tree as "CUSTOM"/101. In your code, you can load this resource with:

    Code:
    mstrName() = Split(StrConv(LoadResData(101, "CUSTOM"), vbUnicode), vbNewLine)
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  13. #13

    Thread Starter
    Hyperactive Member jokerfool's Avatar
    Join Date
    Dec 2006
    Location
    Gold Coast, Australia
    Posts
    452

    Re: Contents of Txt file placed in a BAS file instead

    Hmmm no I dont need something like this that is insecure. I will do some more research about storing the website links within the software. Thank you.

  14. #14
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    928

    Re: Contents of Txt file placed in a BAS file instead

    Quote Originally Posted by Bonnie West View Post
    The manual says:





    You may embed your text file in the exe by adding it to the String Table or, if you want to save space and your text file is ANSI, by importing it as a custom resource. The following instructions are for the custom resource:

    In the VB Resource Editor window (Add-Ins >> Add-In Manager >> VB 6 Resource Editor), click the toolbar button that has the tooltip "Add Custom Resource...". Select your text file from the dialog that shows up. It would probably appear in your resource tree as "CUSTOM"/101. In your code, you can load this resource with:

    Code:
    mstrName() = Split(StrConv(LoadResData(101, "CUSTOM"), vbUnicode), vbNewLine)
    He was thinking on RUNTIME, not DEVELOPTIME.

  15. #15
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    928

    Re: Contents of Txt file placed in a BAS file instead

    Quote Originally Posted by jokerfool View Post
    Hmmm no I dont need something like this that is insecure. I will do some more research about storing the website links within the software. Thank you.
    the best you can do is make that your app gets upgrade itself when it detects that is an upgrade.

    for doing that use the MSINET.OCX component from microsoft, it allows to navigate and to download files from internet.

    Include an MD5 module, for checking MD5 signs, and store in the internet the signs-list (a text cryped file containing all md5 signs), so only you can upgrade that file, and to close the security.

    When your app starts, first check a flag-file in a webserver that tells the current version of the APP, if the version that is running don't match, the app run its installer/upgrader, and ends.

    then, the installer/upgrader do all the work of upgrading the app, then runs again your app. If it is fast, and your webserver works ok, the user will see a pause of seconds.

    THIS METHOD SAVE a lot but A LOT of customer's support work.

  16. #16
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Contents of Txt file placed in a BAS file instead

    Quote Originally Posted by jokerfool View Post
    Hmmm no I dont need something like this that is insecure. I will do some more research about storing the website links within the software. Thank you.
    I believe that's where cryptography comes in. You could encryt your files or strings and hide it in plain view.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  17. #17
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    928

    Re: Contents of Txt file placed in a BAS file instead

    Quote Originally Posted by Bonnie West View Post
    I believe that's where cryptography comes in. You could encryt your files or strings and hide it in plain view.
    Yes, the best way is to ENCRIPT, and for avoid problems with format, to express the crypted result in PLAIN TEXT HEXADECIMAL CODED LIKE.

    00323F4143.......

    then internaly, do:
    Code:
    '...
    dim RawS as string
    dim CodedS as string
    dim UncodedS as string
    dim X as integer
    
    while not eof(1)
        line input#1, RawS
        CodedS=""
        if len(RawS)>0 then
             for x=1 to len(RawS)-1 step 2
                 CodedS=CodedS+chr$(Val("&H"+mid$(RawS,x,2)))
             next x
        endif 
        ' Decode
        UncodedS=YourDecoder(CodedS)
        print#2, UncodedS
    wend
    that way you don't have problems with corrupting the CRCL text file format.

  18. #18

    Thread Starter
    Hyperactive Member jokerfool's Avatar
    Join Date
    Dec 2006
    Location
    Gold Coast, Australia
    Posts
    452

    Re: Contents of Txt file into Form

    Please see the first post as I have included the project and also made some changes.

  19. #19
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Contents of Txt file into Form

    i am just wondering why encrypt the strings? they are just search sites.... anyway you are going to see them as soon as you navigate to them

    why dont you just do a basic encryption? dont need anything fancy as you will see it as soon as you navigate

  20. #20

    Thread Starter
    Hyperactive Member jokerfool's Avatar
    Join Date
    Dec 2006
    Location
    Gold Coast, Australia
    Posts
    452

    Re: Contents of Txt file into Form

    Crikey why is everyone talking encryption, I dont care about encryption, i just want to place the search engines from the text file into the actual form, that is all.

  21. #21
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Contents of Txt file into Form

    ok, so what is the problem then? do you want it to be permenantly into the form or you want to load at Form_Load?

    i dont see why you dont use as resource file... that way its in the app already, if not then just load a form load

  22. #22
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Contents of Txt file into Form

    i made three examples in the attached zip

    1. Load From Res File
    2. Load From Text File
    3. Use Text File To Search (easily switch to Res file, i have included example)

    Code:
    Private ResLines() As String
    Private FileLines() As String
    Private SearchEngines() As String
    
    
    Private Sub cmdSearch_Click()
    '*****Load from res File******
    'SearchEngines = Split(ResLines(Combo3.ListIndex), ",")
    'Debug.Print "Navigate to " & Replace(Replace(SearchEngines(1), Chr(34), ""), "###", Replace(Text1.Text, " ", Replace(SearchEngines(2), Chr(34), vbNullString)))
    
    
    '*****Load from text File******
    SearchEngines = Split(FileLines(Combo3.ListIndex), ",")
    Debug.Print "Navigate to " & Replace(Replace(SearchEngines(1), Chr(34), ""), "###", Replace(Text1.Text, " ", Replace(SearchEngines(2), Chr(34), vbNullString)))
    
    End Sub
    
    Private Sub Combo3_DropDown()
    
    '*******Loading from Res File Here*******
    'Dim i As Integer
    '  If Combo3.ListCount = 0 Then
    '    ResLines = Split(StrConv(LoadResData("SearchEngine.txt", "SearchEngine"), vbUnicode), vbNewLine)
    '      For i = 0 To UBound(ResLines)
    '        SearchEngines = Split(ResLines(i), ",")
    '        Combo3.AddItem Replace(SearchEngines(0), Chr(34), vbNullString)
    '      Next
    '  End If
    
    
    '*******Loadin from text File**********
    Dim i As Integer 'Already in this sub (for res file)
    Dim FF As Integer
    Dim sTempText As String
    Dim sTextLine As String
    
    If Combo3.ListCount = 0 Then
      FF = FreeFile
      
      Open App.Path & "\SearchEngine.txt" For Input As #FF
        Do Until EOF(FF)
          Line Input #FF, sTextLine
            sTempText = sTempText & sTextLine & vbNewLine
        Loop
      Close #FF
      
      sTempText = Left(sTempText, Len(sTempText) - Len(vbNewLine)) 'Remove Last Unnecessary vbNewLine
      FileLines = Split(sTempText, vbNewLine)
        
      For i = 0 To UBound(FileLines)
        SearchEngines = Split(FileLines(i), ",")
        Combo3.AddItem Replace(SearchEngines(0), Chr(34), vbNullString)
      Next
    End If
    End Sub
    
    Private Sub Command1_Click()
    Dim i As Integer
      ResLines = Split(StrConv(LoadResData("SearchEngine.txt", "SearchEngine"), vbUnicode), vbNewLine)
        For i = 0 To UBound(ResLines)
          SearchEngines = Split(ResLines(i), ",")
          Combo1.AddItem Replace(SearchEngines(1), Chr(34), vbNullString)
        Next
    End Sub
    
    Private Sub Command2_Click()
    Dim i As Integer
      ResLines = Split(StrConv(LoadResData("SearchEngine.txt", "SearchEngine"), vbUnicode), vbNewLine)
        For i = 0 To UBound(ResLines)
          SearchEngines = Split(ResLines(i), ",")
          List1.AddItem Replace(SearchEngines(1), Chr(34), vbNullString)
        Next
    End Sub
    
    Private Sub Command3_Click()
    Dim i As Integer
    Dim FF As Integer
    Dim sTempText As String
    Dim sTextLine As String
    
    FF = FreeFile
    
    Open App.Path & "\SearchEngine.txt" For Input As #FF
      Do Until EOF(FF)
        Line Input #FF, sTextLine
          sTempText = sTempText & sTextLine & vbNewLine
      Loop
    Close #FF
    
    sTempText = Left(sTempText, Len(sTempText) - Len(vbNewLine)) 'Remove Last Unnecessary vbNewLine
    FileLines = Split(sTempText, vbNewLine)
      
    For i = 0 To UBound(FileLines)
      SearchEngines = Split(FileLines(i), ",")
      List2.AddItem Replace(SearchEngines(1), Chr(34), vbNullString)
    Next
    End Sub
    
    Private Sub Command4_Click()
    Dim i As Integer
    Dim FF As Integer
    Dim sTempText As String
    Dim sTextLine As String
    
    FF = FreeFile
    
    Open App.Path & "\SearchEngine.txt" For Input As #FF
      Do Until EOF(FF)
        Line Input #FF, sTextLine
          sTempText = sTempText & sTextLine & vbNewLine
      Loop
    Close #FF
    
    sTempText = Left(sTempText, Len(sTempText) - Len(vbNewLine)) 'Remove Last Unnecessary vbNewLine
    FileLines = Split(sTempText, vbNewLine)
      
    For i = 0 To UBound(FileLines)
      SearchEngines = Split(FileLines(i), ",")
      Combo2.AddItem Replace(SearchEngines(1), Chr(34), vbNullString)
    Next
      
    End Sub
    of course i would not keep it like this... i would make it alot better, and remove some code but all I did was show you an example of how to from from Text File or Res File
    Attached Files Attached Files

  23. #23

    Thread Starter
    Hyperactive Member jokerfool's Avatar
    Join Date
    Dec 2006
    Location
    Gold Coast, Australia
    Posts
    452

    Re: Contents of Txt file into Form

    I dont use the res file because I already have a res file and noticed that I couldnt have 2 of them.

  24. #24

    Thread Starter
    Hyperactive Member jokerfool's Avatar
    Join Date
    Dec 2006
    Location
    Gold Coast, Australia
    Posts
    452

    Re: Contents of Txt file into Form

    I basically dont want the res file and wanted to delete the text file and just have what is in the text file into the form instead. Thank you for the reply.

  25. #25
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Contents of Txt file into Form

    ok i see well do this

    Code:
    Dim sTextFile As String
    sTextFile = "Google,www.website1.com,+" & vbNewLine & _
                     "Yahoo,www.website2.com,+" & vbNewLine & _
                     "Bing,www.website3.com,+"
    'and on and on just put & vbNewLine & _
    you could even do it with code (if very big file)
    use the example i put to load file but instead of adding to array add to a textbox/string and then just copy/clipboard and paste it in your form under a string like i showed you then it will always be in your form, no need for extra file or anything... like you first said use a bas module so its not bugging you when coding the form? or just simply put it on the form!

    i thought you would know how to do this?

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