LOL Back again

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
11 posts Page 1 of 2
Contributors
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

LOL Back again
muttley1968
people i know how to edit a textfile but how would i edit one line in a hole load so
the file is laied out like this

music:0.0
sound:0.0
invertYMouse:false
mouseSensitivity:0.2535211
fov:0.0
gamma:1.0
viewDistance:2
guiScale:0
particles:1
bobView:false
anaglyph3d:false
advancedOpengl:false
fpsLimit:100
difficulty:2
fancyGraphics:false
ao:false
clouds:false
skin:DokuCraft - The Saga Continues 1.2.5 - Light.zip
lastServer:
lang:en_US


and i want to replace the skin: (texturepack)
and that line only
User avatar
comathi
Coding God
Coding God
Posts: 1242
Joined: Fri Mar 26, 2010 1:59 pm

Re: LOL Back again
comathi
Well, an easier way to seperate your items would be to end each one with ";" or another special character. It would look something like this:

music:0.0;sound0.0;blabla:bloblabli; , etc. Then, you could use the following code to edit that single item:
Code: Select all
Dim str As String = My.Computer.ReadAllText("filename")
Dim list() As String = str.Split(";")
list(17)="New value" 'Keep in mind that the number 17 represents the order of that item in the list-1 (the index of the item). You can change it to any value between 0 and list.lengh-1 to control another item.
My.Computer.WriteAllText("filename", false)
This should work splendidly ;)
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: LOL Back again
mandai
If you need to keep the lines in the same format you can use this:
Code: Select all
    Private Sub btnUpdate_Click(sender As System.Object, e As System.EventArgs) Handles btnUpdate.Click

        Dim lines As String() = File.ReadAllLines("file.txt")
        For i As Integer = 0 To lines.Length - 1

            If lines(i).StartsWith("skin:") Then
                lines(i) = "skin:test"
            End If
        Next
        File.WriteAllLines("file.txt", lines)

    End Sub
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Re: LOL Back again
muttley1968
i need to get just the file name out of something soo C:/user/document/Texture.rar now all i want it the texture.rar section but need to take it from the textbox that says user blah blah my dad sujest using a instr function but i am unsure on how to use this does anyone else know how
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: LOL Back again
mandai
The above sample shows how to edit one line.
sujest using a instr function
You would use the String.Remove function.

You can get the skin value by adding this:
Code: Select all
            If lines(i).StartsWith("skin:") Then
                Dim skin As String = lines(i).Remove(0, 5)
                MsgBox(skin)
            End If
User avatar
Ffenixw0rks
VIP - Donator
VIP - Donator
Posts: 152
Joined: Sun Jun 19, 2011 2:51 pm

Re: LOL Back again
Ffenixw0rks
Use like comathi said, just replace ; with vbNewLine.
Image
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Re: LOL Back again
muttley1968
hmm how to explain right well in mincraft the way it reads what texturepack to use it by looking in options and it says Skin:default and that will load the default soo my program moves the texturepack to the right folder at the min and to apply it i need it to take the text from a box that has is orginal location such as C:/users/muttley/document/newpack.zip and then take the text in the newpack.zip section and replace just the skin part of option with something like sking:newpack.zip so next time it is loaded it will load the new one but i have to do this inside one line of code so that it can be used in the same event as the move if you need more explenation ask and ill add you on skype and show you what i mean
User avatar
comathi
Coding God
Coding God
Posts: 1242
Joined: Fri Mar 26, 2010 1:59 pm

Re: LOL Back again
comathi
Well, to get just the file.name part of a file, use this:
Code: Select all
Dim fullName As String="C:\Users\blah\blahblah\file.name"
Dim fileName As String= fullName.SubString(fullName.LastIndexOf("\")+1)
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: LOL Back again
MrAksel
Comathi, wayy easier :)
Code: Select all
Dim FileName As String = System.IO.Path.GetFileName("C:\Users\You\Personal documents\Hidden documents\Secured documents\Hidden Images.zip")
The full code would be
Code: Select all
    Private Sub btnUpdate_Click(sender As System.Object, e As System.EventArgs) Handles btnUpdate.Click
        Dim skin As String = System.IO.Path.GetFileName(TextBox1.Text)
        Dim lines As String() = File.ReadAllLines("file.txt")
        For i As Integer = 0 To lines.Length - 1

            If lines(i).StartsWith("skin:") Then
                lines(i) = "skin:" + skin
            End If
        Next
        File.WriteAllLines("file.txt", lines)

    End Sub
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
User avatar
muttley1968
Hardcore Programmer
Hardcore Programmer
Posts: 622
Joined: Thu Jun 17, 2010 11:54 pm

Re: LOL Back again
muttley1968
I have finished it it is all ready would you like me to put it online or not people
11 posts Page 1 of 2
Return to “Coding Help & Support”