Results 1 to 21 of 21

Thread: my code not works

  1. #1

    Thread Starter
    Hyperactive Member gaouser's Avatar
    Join Date
    Mar 2022
    Location
    Near the User32.dll
    Posts
    386

    my code not works

    im trying to read 2 line but not works

    Code:
                        Dim myOpenFileDialog As New OpenFileDialog()
            myOpenFileDialog.Filter = "Android Belgesi (*.and)|*.and|Android Datalı Dosyalar (*.*)|*.*"
    
    
            If myOpenFileDialog.ShowDialog = DialogResult.OK Then
                Dim fileReader As System.IO.StreamReader
                fileReader =
                My.Computer.FileSystem.OpenTextFileReader(myOpenFileDialog.FileName)
                Dim stringReader As String
                Dim stringReader2 As String
                stringReader = fileReader.ReadLine(0)
                stringReader2 = fileReader.ReadLine(1)
    
    
    
    
                Dim ChildForm As New Form1
                ' Make it a child of this MDI form before showing it.
                ChildForm.MdiParent = Me
    
                m_ChildFormNumber += 1
                ChildForm.Text = "Android" & m_ChildFormNumber
    
                Dim oldx As Single
                oldx = ChildForm.PictureBox1.Left + ChildForm.PictureBox1.Width / 2   'find current center()
                ChildForm.PictureBox1.Width = stringReader
    
    
                ChildForm.PictureBox1.Left = oldx - ChildForm.PictureBox1.Width / 2   'find new left
    
                Dim oldx2 As Single
                oldx2 = ChildForm.PictureBox2.Left + ChildForm.PictureBox2.Width / 2   'find current center()
                ChildForm.PictureBox2.Width = stringReader2
    
    
                ChildForm.PictureBox2.Left = oldx2 - ChildForm.PictureBox2.Width / 2   'find new left
                ChildForm.Show()
            End If
    Last edited by gaouser; Apr 13th, 2022 at 03:54 PM.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: my code not works

    So what's it doing or what's it not doing? You certainly need to be turning Option Strict ON and fixing the errors that will then show up, since you are assigning a string to a property that takes an integer. If the string looks like an integer, then that will work with Option Strict OFF, but it's not reliable. What you should be doing is using either Integer.TryParse, or CInt() to convert the string to an integer explicitly. You'd use TryParse if you aren't certain whether it is a string (if you got the string from the user, for example), and use CInt if you are CERTAIN that the string can be converted to an integer.

    In this case, it sounds like you aren't getting what you expect back from ReadLine, but that isn't clear.
    My usual boring signature: Nothing

  3. #3
    Fanatic Member Peter Porter's Avatar
    Join Date
    Jul 2013
    Posts
    532

    Re: my code not works

    Quote Originally Posted by gaouser View Post
    im trying to read 2 line but not works

    Code:
                Dim stringReader As String
                Dim stringReader2 As String
                stringReader = fileReader.ReadLine(0)
                stringReader2 = fileReader.ReadLine(1)
    
    
    
    
                Dim ChildForm As New Form1
                ' Make it a child of this MDI form before showing it.
                ChildForm.MdiParent = Me
    
                m_ChildFormNumber += 1
                ChildForm.Text = "Android" & m_ChildFormNumber
    
                Dim oldx As Single
                oldx = ChildForm.PictureBox1.Left + ChildForm.PictureBox1.Width / 2   'find current center()
                ChildForm.PictureBox1.Width = stringReader
    
    
                ChildForm.PictureBox1.Left = oldx - ChildForm.PictureBox1.Width / 2   'find new left
    
                Dim oldx2 As Single
                oldx2 = ChildForm.PictureBox2.Left + ChildForm.PictureBox2.Width / 2   'find current center()
                ChildForm.PictureBox2.Width = stringReader2
    
    
                ChildForm.PictureBox2.Left = oldx2 - ChildForm.PictureBox2.Width / 2   'find new left
                ChildForm.Show()
            End If
    I can't believe my eyes! Code!

    Gaousy posted code!!!

  4. #4

    Thread Starter
    Hyperactive Member gaouser's Avatar
    Join Date
    Mar 2022
    Location
    Near the User32.dll
    Posts
    386

    Re: my code not works

    what, read title

  5. #5

    Thread Starter
    Hyperactive Member gaouser's Avatar
    Join Date
    Mar 2022
    Location
    Near the User32.dll
    Posts
    386

    Re: my code not works

    in extra stop calling me as Gaousy my name is shourtcut to (Google android oyunları (Fan Made) VB forum User)

  6. #6

    Thread Starter
    Hyperactive Member gaouser's Avatar
    Join Date
    Mar 2022
    Location
    Near the User32.dll
    Posts
    386

    Re: my code not works

    yes moderator not working im making androidify remake on vb.net (im gonna stop vb6 version)

  7. #7
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: my code not works

    When you step through the code with the debugger, at what point does it not do what you expect it to do?
    For instance
    Code:
                stringReader = fileReader.ReadLine(0)
                stringReader2 = fileReader.ReadLine(1)
    When you step through those lines were the variables set to the strings you expected from the file?
    And if they worked, then continue stepping until what you expect to happen didn't happen.
    You can get better help if you identify the line where the code doesn't do what you expect it to do and you point it out.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  8. #8

    Thread Starter
    Hyperactive Member gaouser's Avatar
    Join Date
    Mar 2022
    Location
    Near the User32.dll
    Posts
    386

    Re: my code not works

    2st string reader gives me 0 not 2st line (i changed 1 to 2)

  9. #9

    Thread Starter
    Hyperactive Member gaouser's Avatar
    Join Date
    Mar 2022
    Location
    Near the User32.dll
    Posts
    386

    Re: my code not works

    inside of my file is

    192
    200

    these are width for head and body (i have plan.im gonna create a function) and merge these

  10. #10
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: my code not works

    Unless I am missing something ReadLine doesn't take an integer, it just returns the next line https://docs.microsoft.com/en-us/dot...eader-readline so I am not even sure how that code compiles.

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: my code not works

    This is a perfect example of why you need to pay attention to Intellisense at least and, better yet, read the documentation when using types and members that you're not familiar with. This code:
    vb.net Code:
    1. stringReader = fileReader.ReadLine(0)
    2. stringReader2 = fileReader.ReadLine(1)
    is very bad. If you actually intended what it's actually doing then it's very poorly written but I'm certain that that's not what you intended. That code is actually doing this:
    vb.net Code:
    1. stringReader = fileReader.ReadLine().Chars(0)
    2. stringReader2 = fileReader.ReadLine().Chars(1)
    You appear to be trying to tell the StreamReader which line to read, but there is no such ReadLine method, which you would know if you had paid attention to Intellisense or read the documentation. ReadLine has no parameters and simply reads the next line. Because you tried to pass an argument, the compiler assumed that you were actually calling ReadLine without parentheses and then indexing the String that it returns. That means that the first line of code will read the first line of the file and return the first character from that line and assign it to the variable, then the second line of code will read the second line of the file and return the second character from it and assign that to the variable. Just get rid of the numbers and it will work as I suspect you want it to.

  12. #12

    Thread Starter
    Hyperactive Member gaouser's Avatar
    Join Date
    Mar 2022
    Location
    Near the User32.dll
    Posts
    386

    Re: my code not works

    just gives me 0

  13. #13

    Thread Starter
    Hyperactive Member gaouser's Avatar
    Join Date
    Mar 2022
    Location
    Near the User32.dll
    Posts
    386

    Re: my code not works

    1st one gived me 1 2st one gived me 2 but its not on the file i write

  14. #14
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: my code not works

    Show the updated code you used and show the content of the file.

  15. #15
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,235

    Re: my code not works

    Quote Originally Posted by gaouser View Post
    (im gonna stop vb6 version)
    No, already? I needed it next month...
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  16. #16
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: my code not works

    He showed the content of the file in post #9.
    It seems he didn't understand jmc's post #11, and is still using an index parameter so is now reading the first character of each line, rather than the whole line.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  17. #17
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: my code not works

    Yes sorry, I missed that.
    Then it's clear he didn't changed his code to just do a ReadLine without a parameter

  18. #18
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: my code not works

    y'all are trying too hard ... let me see if I can translate it into gaousereesee...

    no work...
    Code:
        stringReader = fileReader.ReadLine(0)
        stringReader2 = fileReader.ReadLine(1)
    yes work...
    Code:
        stringReader = fileReader.ReadLine()
        stringReader2 = fileReader.ReadLine()

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  19. #19
    Fanatic Member Peter Porter's Avatar
    Join Date
    Jul 2013
    Posts
    532

    Re: my code not works

    Quote Originally Posted by techgnome View Post
    y'all are trying too hard ... let me see if I can translate it into gaousereesee...

    no work...
    Code:
        stringReader = fileReader.ReadLine(0)
        stringReader2 = fileReader.ReadLine(1)
    yes work...
    Code:
        stringReader = fileReader.ReadLine()
        stringReader2 = fileReader.ReadLine()

    -tg
    Your Gaouserish is pretty good!

  20. #20
    Fanatic Member Peter Porter's Avatar
    Join Date
    Jul 2013
    Posts
    532

    Re: my code not works

    Gaouser, why does your PictureBoxes have to get their size and location from a file? Wouldn't it be easier if you just assigned everything under the Picturebox properties, and then code it so your PictureBoxes dynamically change it's size and location according to certain conditions?

    What exactly are you using the PictureBoxes for?
    Last edited by Peter Porter; Apr 14th, 2022 at 09:28 AM.

  21. #21

    Thread Starter
    Hyperactive Member gaouser's Avatar
    Join Date
    Mar 2022
    Location
    Near the User32.dll
    Posts
    386

    Re: my code not works

    these are creating a android logo

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