-1

so you have pretty much read the title,

I want to make it so that any value in ResolutionSizeX= is going to become 1920 every single number.

Heres my code:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    My.Computer.FileSystem.WriteAllText("C:\Users\NarpZ\AppData\Local\FortniteGame\Saved\Config\WindowsClient\GameUserSettings.ini",
    My.Computer.FileSystem.ReadAllText("C:\Users\NarpZ\AppData\Local\FortniteGame\Saved\Config\WindowsClient\GameUserSettings.ini").Replace("ResolutionSizeX=", "ResolutionSizeX=1920"),
    False)

End Sub
Visual Vincent
  • 18,045
  • 5
  • 28
  • 75
Alexandra
  • 5
  • 4
  • 1
    What's your question? Is something not working as expected? What isn't working? Which step along the way is the first to fail? (Hint: Separate your operations into individual lines of code to observe them one at a time while debugging.) What data is in your file? Please specify the problem. – David Jan 02 '19 at 13:09
  • I wanted every single number that is possible in it to become 1920, if it is like 1628 or 980 or 16 or 12034 you understand? – Alexandra Jan 02 '19 at 13:14
  • what do you mean about "Can you do it in a text editor which supports regular expressions?" – Alexandra Jan 02 '19 at 13:25
  • check this out to edit INI files - https://stackoverflow.com/questions/217902/reading-writing-an-ini-file – Ctznkane525 Jan 02 '19 at 13:33
  • Im doing this in visual basic. When I tried it, it didn't work. – Alexandra Jan 02 '19 at 13:46
  • Please do not edit the title of a question to indicate that the problem has been solved. Stack Overflow is already specifically designed (both internally and SEO-wise) to indicate that by moving the accepted answer to the top and displaying the "answer count" in green in the list of questions. For the same reasons it is also not necessary to add the name of the programming language in the title unless it serves a specific purpose, as both displaying and filtering by language is already taken care of by the tags. – Visual Vincent Jan 02 '19 at 14:41
  • For reference and more information please see [Is it OK to add \[Solved\] to the title of a question?](https://meta.stackexchange.com/q/116101) and [Should questions include "tags" in their titles?](https://meta.stackexchange.com/q/19190) Thank you! – Visual Vincent Jan 02 '19 at 14:46

1 Answers1

0

Untested but it should do the trick.

    Dim strFile As String = "C:\Users\NarpZ\AppData\Local\FortniteGame\Saved\Config\WindowsClient\GameUserSettings.ini"

  If System.IO.File.Exists(strFile) Then

    Dim arrLines() As String = IO.File.ReadAllLines(strFile)

    For i As Integer = 0 To arrLines.Length - 1
        If Strings.Left(arrLines(i),16)="ResolutionSizeX=" Then
            arrLines(i) = "ResolutionSizeX=1920" 
        End If
    Next

    System.IO.File.WriteAllLines(strFile, arrLines) 'SAVE

  End If
Thomas G
  • 9,886
  • 7
  • 28
  • 41
  • It does the trick, but if I have something named LastUserConfirmedResolutionSizeX it changes that too to ResolutionSizeX. – Alexandra Jan 02 '19 at 14:14
  • @Narpzy adapted the code so it checks if the 16 first chars of the line are *ResolutionSizeX=*, and not simply contain the string – Thomas G Jan 02 '19 at 14:20
  • I just tried to do the same with LastUserConfirmedResolutionSizeX, and it didn't work, heres the code: If System.IO.File.Exists(strFile) Then Dim arrLines() As String = IO.File.ReadAllLines(strFile) For i As Integer = 0 To arrLines.Length - 1 If Strings.Left(arrLines(i), 16) = "ResolutionSizeX=" Then arrLines(i) = "ResolutionSizeX=1920" ElseIf Strings.Left(arrLines(i), 16) = "LastUserConfirmedResolutionSizeX=" Then arrLines(i) = "LastUserConfirmedResolutionSizeX=1920" End If Next System.IO.File.WriteAllLines(strFile, arrLines) 'SAVE End If – Alexandra Jan 02 '19 at 14:28
  • Remove the `File.Exists()` check. It's almost always counter-productive, and usually makes things slower; you're normally better off just handling the exception. – Joel Coehoorn Jan 02 '19 at 14:35
  • If you want to make it work with other variables, you have to adapt the 16 in the Left instruction. 16 is the number of chars in your string, including the = at the end – Thomas G Jan 02 '19 at 14:36
  • @JoelCoehoorn was fasted to code then a ctach try block (I have no VS here atm) :-) – Thomas G Jan 02 '19 at 14:37
  • ok, that helped me out. – Alexandra Jan 02 '19 at 14:41