Micah C Posted January 26, 2009 Posted January 26, 2009 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 Quote
nullArray Posted January 26, 2009 Posted January 26, 2009 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. Quote
Scorpion Posted January 26, 2009 Posted January 26, 2009 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) Quote
Micah C Posted January 27, 2009 Author Posted January 27, 2009 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\" & findwidget.Text & ".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 Quote
cooper Posted January 27, 2009 Posted January 27, 2009 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\" & findwidget.Text & ".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. Quote
Scorpion Posted January 27, 2009 Posted January 27, 2009 Yea i like yours better Cooper :) (i might of missed something in my code but i would go with cooper as its easier and would be faster.) Quote
SomethingToChatWith Posted January 28, 2009 Posted January 28, 2009 I use a select case statement in my loop with every possible bit of info the app needs to get info from the file and use it and system.io.file.opentext to open the handler. For string manipulation use the lset() and mid() functions. Quote
Micah C Posted February 2, 2009 Author Posted February 2, 2009 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 Quote
SomethingToChatWith Posted February 3, 2009 Posted February 3, 2009 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... Quote
Micah C Posted February 3, 2009 Author Posted February 3, 2009 Ok Thanks ill try that out. I think my problem was that I needed to add another variable "Temp2" but well see. Quote
SomethingToChatWith Posted February 4, 2009 Posted February 4, 2009 Yeah... you start out thinking you only need x ammount of variables, but depending on the task don't be surprised to finish the project with twice as much. It's all about going back once you have a solution that works to clean it up. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.