Jump to content

Recommended Posts

Posted

Hello Hak5,

I am writing an application in VB.NET 2008 that runs a users compiled widget. The user opens notepad and enters something like this:

[GUI]
This is my text for the form
[ClockApp]
24 hrs
[BackgroundColor]
Black
[Size]
X:
Y:
[Details]
Author:
Date:
Text:
Color:
Image:
[/Done]
#Widget#

I would like my program to read the lines of text then respond accordingly. So the first line of code is "[GUI]" this tells the program that the interface should be GUI, the second line is just text. The text should be displayed on the GUI form. so on and so forth. Is this to complicated any help or ideas is appreciated.

Micah C

Posted
Hello Hak5,

I am writing an application in VB.NET 2008 that runs a users compiled widget. The user opens notepad and enters something like this:

[GUI]
This is my text for the form
[ClockApp]
24 hrs
[BackgroundColor]
Black
[Size]
X:
Y:
[Details]
Author:
Date:
Text:
Color:
Image:
[/Done]
#Widget#

I would like my program to read the lines of text then respond accordingly. So the first line of code is "[GUI]" this tells the program that the interface should be GUI, the second line is just text. The text should be displayed on the GUI form. so on and so forth. Is this to complicated any help or ideas is appreciated.

Micah C

I know nothing of VB, but isn't there a way to capture lines of text and iterate character by character while ignoring x amount of characters?

That way you could say something like:

lineCapture <- input stream of the line (lets say it's the "Author: " line)

Ignore the first 8 characters, then capture the rest into a string or character array?

I had to so something very similar two years ago in C++..., so I'm going off of that.

Posted

This is how i've been told to do it. (vb 05)

Dim fileReader As System.IO.StreamReader
        Dim Temp,GUI,ClockAPP As String

        Try
            fileReader = My.Computer.FileSystem.OpenTextFileReader(FILENAME, System.Text.ASCIIEncoding.UTF7)
            Temp = fileReader.ReadLine()

            Do Until fileReader.EndOfStream = True
                If Temp = "GUI" Then 
                    GUI = FileReader.readline
                elseIf Temp = "ClockApp" then
                   ClockAPP =  FileReader.readline
           loop
       catch ex as exception
       end try

Everytime FileReader.readline is called it reads the next line

Hope that helps :D (i can only program Pascal, alittle DOS, VB6 and VB.net 05)

Posted

Hello,

So i tried your code. ( Scorpion ). I made a few changes to suit my needs. There is one problem tho. It is not executing the second result.

    Dim fileReader As System.IO.StreamReader
        Dim Temp, GUI, ClockAPP As String

        Try
            fileReader = My.Computer.FileSystem.OpenTextFileReader("C:\Widget App\" &amp; findwidget.Text &amp; ".widget", System.Text.ASCIIEncoding.UTF7)
            Temp = fileReader.ReadLine()

            Do Until fileReader.EndOfStream = True
                If Temp = "GUI" Then
                    GUI = fileReader.ReadLine
                    Dim mywidget As New Form
                    mywidget.Show() ' Result here.'

                    ' Probrlem: Not executing the second result

                    If Temp = "ClockApp" Then
                        ClockAPP = fileReader.ReadLine
                        Dim form2 As New Form
                        form2.Show() ' Result here.'


                    End If
                End If

            Loop

        Catch ex As Exception
        End Try

        Me.Close()

If i want to execute the second result would I have to change "Temp" to like "Temp2"? Any ideas?

Micah C

Posted

You shouldn't nest those IFs, and you probably want to read a new line for each iteration of the Do Until loop. Like this:

    Dim fileReader As System.IO.StreamReader
        Dim Temp, GUI, ClockAPP, bgColor, sizeX, sizeY As String

        Try
            fileReader = My.Computer.FileSystem.OpenTextFileReader("C:\Widget App\" &amp; findwidget.Text &amp; ".widget", System.Text.ASCIIEncoding.UTF7)

            Do Until fileReader.EndOfStream = True
                Temp = fileReader.ReadLine()
                If Temp = "[GUI]" Then
                    GUI = fileReader.ReadLine
                    Dim mywidget As New Form
                    mywidget.Show() ' Result here.'
                elseIf Temp = "[ClockApp]" Then
                    ClockAPP = fileReader.ReadLine
                    Dim form2 As New Form
                    form2.Show() ' Result here.'
                elseIf Temp = "[BackgroundColor]" Then
                    bgColor = fileReader.ReadLine
                elseIf Temp = "[Size]" Then
                    sizeX = fileReader.ReadLine
                    sizeY = fileReader.ReadLine
                End If
            Loop
        Catch ex As Exception
        End Try

        Me.Close()

Note that while I do program quite a bit, I'm not a VB programmer by any means.

Posted

Hey thanks a lot Cooper. Your code really helps and i have been able to develop a nice widget program. I have a final probrlem tho. how do i deal with additional text that isn't a command. Say i wanted my new form to have its text value equil whatever text is below "[GUI]". How would I work with that? any ideas?

[GUI] 
This is my text for the form

Posted

If temp = "[GUI]" Then Form2.Text = FileReader.ReadLine()

If you need to use the input for more than that, put it in the temp or another variable first and reference the value, say like this assuming its put in a variable called temp2:

If temp = "[GUI]" Then temp2 = FileReader.ReadLine()

additional actions to do using temp2...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...