Results 1 to 7 of 7

Thread: newbie vb question

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    1

    newbie vb question

    Hey I have kind of a newbie question, I'm trying to make a little joke application for my friend, and untill I can go to the store and pick up a VB book can you guys help me out?

    I got a Form, with one button and on textbox. You can't type in the text box.

    what i'm trying to do is make a little string array to make a program that does this:

    when you hit the button, it enters into TextBox1 = MyStringArray(0), then when you hit it again it does MyStringArray(1), then MyStringArray(2), then MyStringArray(3), then when its again go back to MyStringArray(0).

    is there an easy/simple way to do this? im hoping to get it made by tommorow.
    thanks guys and sorry for the extremely newbie question

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: newbie vb question

    Welcome to the forums! Try something like this:
    VB Code:
    1. Option Explicit
    2.  
    3. Dim str(3) As String
    4. Dim x As Integer
    5.  
    6. Private Sub Command1_Click()
    7.   Text1.Text = str(x)
    8.   x = x + 1
    9.   x = x Mod 4
    10. End Sub
    11.  
    12. Private Sub Form_Load()
    13.   str(0) = "David "
    14.   str(1) = "is "
    15.   str(2) = "the "
    16.   str(3) = "Best!"
    17. End Sub

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: newbie vb question

    Quote Originally Posted by dglienna
    Welcome to the forums! Try something like this:
    VB Code:
    1. Option Explicit
    2.  
    3. Dim str(3) As String
    4. Dim x As Integer
    5.  
    6. Private Sub Command1_Click()
    7.   Text1.Text = str(x)
    8.   x = x + 1
    9.   x = x Mod 4
    10. End Sub
    11.  
    12. Private Sub Form_Load()
    13.   str(0) = "David "
    14.   str(1) = "is "
    15.   str(2) = "the "
    16.   str(3) = "Best!"
    17. End Sub
    This is the VB.NET forum and not Classic VB forum (VB6). newbieVB101011, which version of VB are you using?

    This is the correct way in VB.NET to do it.

    VB Code:
    1. Dim MyStringArray(3) As String
    2. Dim i As Integer = 0
    3.  
    4. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    5.     MyStringArray(0) = "Test 0"
    6.     MyStringArray(1) = "Test 1"
    7.     MyStringArray(2) = "Test 2"
    8.     MyStringArray(3) = "Test 3"
    9. End Sub
    10.  
    11. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    12.     TextBox1.Text = MyStringArray(i)
    13.     i += 1
    14.     If i > 3 Then i = 0
    15. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: newbie vb question

    Oops. Happy New Year! "New Posts" strikes again!

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: newbie vb question

    Well not really as the thread starter has not identifed which version he is using. Could go either way and now hes got answers for both.

    Happy Pre-New Years!
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: newbie vb question

    HAHAHAHAHA! The first one that the upgrade wizard got right!

    VB Code:
    1. Option Strict Off
    2. Option Explicit On
    3. Friend Class Form1
    4.     Inherits System.Windows.Forms.Form
    5. #Region "Windows Form Designer generated code "
    6.     Public Sub New()
    7.         MyBase.New()
    8.         If m_vb6FormDefInstance Is Nothing Then
    9.             If m_InitializingDefInstance Then
    10.                 m_vb6FormDefInstance = Me
    11.             Else
    12.                 Try
    13.                     'For the start-up form, the first instance created is the default instance.
    14.                     If System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType Is Me.GetType Then
    15.                         m_vb6FormDefInstance = Me
    16.                     End If
    17.                 Catch
    18.                 End Try
    19.             End If
    20.         End If
    21.         'This call is required by the Windows Form Designer.
    22.         InitializeComponent()
    23.     End Sub
    24.     'Form overrides dispose to clean up the component list.
    25.     Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
    26.         If Disposing Then
    27.             If Not components Is Nothing Then
    28.                 components.Dispose()
    29.             End If
    30.         End If
    31.         MyBase.Dispose(Disposing)
    32.     End Sub
    33.     'Required by the Windows Form Designer
    34.     Private components As System.ComponentModel.IContainer
    35.     Public ToolTip1 As System.Windows.Forms.ToolTip
    36.     Public WithEvents Command1 As System.Windows.Forms.Button
    37.     Public WithEvents Text1 As System.Windows.Forms.TextBox
    38.     'NOTE: The following procedure is required by the Windows Form Designer
    39.     'It can be modified using the Windows Form Designer.
    40.     'Do not modify it using the code editor.
    41.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    42.         Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
    43.         Me.components = New System.ComponentModel.Container()
    44.         Me.ToolTip1 = New System.Windows.Forms.ToolTip(components)
    45.         Me.ToolTip1.Active = True
    46.         Me.Command1 = New System.Windows.Forms.Button
    47.         Me.Text1 = New System.Windows.Forms.TextBox
    48.         Me.Text = "Form1"
    49.         Me.ClientSize = New System.Drawing.Size(312, 206)
    50.         Me.Location = New System.Drawing.Point(4, 30)
    51.         Me.StartPosition = System.Windows.Forms.FormStartPosition.WindowsDefaultLocation
    52.         Me.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    53.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    54.         Me.BackColor = System.Drawing.SystemColors.Control
    55.         Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable
    56.         Me.ControlBox = True
    57.         Me.Enabled = True
    58.         Me.KeyPreview = False
    59.         Me.MaximizeBox = True
    60.         Me.MinimizeBox = True
    61.         Me.Cursor = System.Windows.Forms.Cursors.Default
    62.         Me.RightToLeft = System.Windows.Forms.RightToLeft.No
    63.         Me.ShowInTaskbar = True
    64.         Me.HelpButton = False
    65.         Me.WindowState = System.Windows.Forms.FormWindowState.Normal
    66.         Me.Name = "Form1"
    67.         Me.Command1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
    68.         Me.Command1.Text = "Command1"
    69.         Me.Command1.Size = New System.Drawing.Size(81, 33)
    70.         Me.Command1.Location = New System.Drawing.Point(120, 88)
    71.         Me.Command1.TabIndex = 1
    72.         Me.Command1.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    73.         Me.Command1.BackColor = System.Drawing.SystemColors.Control
    74.         Me.Command1.CausesValidation = True
    75.         Me.Command1.Enabled = True
    76.         Me.Command1.ForeColor = System.Drawing.SystemColors.ControlText
    77.         Me.Command1.Cursor = System.Windows.Forms.Cursors.Default
    78.         Me.Command1.RightToLeft = System.Windows.Forms.RightToLeft.No
    79.         Me.Command1.TabStop = True
    80.         Me.Command1.Name = "Command1"
    81.         Me.Text1.AutoSize = False
    82.         Me.Text1.Size = New System.Drawing.Size(81, 33)
    83.         Me.Text1.Location = New System.Drawing.Point(32, 24)
    84.         Me.Text1.TabIndex = 0
    85.         Me.Text1.Text = "Text1"
    86.         Me.Text1.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    87.         Me.Text1.AcceptsReturn = True
    88.         Me.Text1.TextAlign = System.Windows.Forms.HorizontalAlignment.Left
    89.         Me.Text1.BackColor = System.Drawing.SystemColors.Window
    90.         Me.Text1.CausesValidation = True
    91.         Me.Text1.Enabled = True
    92.         Me.Text1.ForeColor = System.Drawing.SystemColors.WindowText
    93.         Me.Text1.HideSelection = True
    94.         Me.Text1.ReadOnly = False
    95.         Me.Text1.Maxlength = 0
    96.         Me.Text1.Cursor = System.Windows.Forms.Cursors.IBeam
    97.         Me.Text1.MultiLine = False
    98.         Me.Text1.RightToLeft = System.Windows.Forms.RightToLeft.No
    99.         Me.Text1.ScrollBars = System.Windows.Forms.ScrollBars.None
    100.         Me.Text1.TabStop = True
    101.         Me.Text1.Visible = True
    102.         Me.Text1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
    103.         Me.Text1.Name = "Text1"
    104.         Me.Controls.Add(Command1)
    105.         Me.Controls.Add(Text1)
    106.     End Sub
    107. #End Region
    108. #Region "Upgrade Support "
    109.     Private Shared m_vb6FormDefInstance As Form1
    110.     Private Shared m_InitializingDefInstance As Boolean
    111.     Public Shared Property DefInstance() As Form1
    112.         Get
    113.             If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
    114.                 m_InitializingDefInstance = True
    115.                 m_vb6FormDefInstance = New Form1()
    116.                 m_InitializingDefInstance = False
    117.             End If
    118.             DefInstance = m_vb6FormDefInstance
    119.         End Get
    120.         Set
    121.             m_vb6FormDefInstance = Value
    122.         End Set
    123.     End Property
    124. #End Region
    125.    
    126.     'UPGRADE_NOTE: str was upgraded to str_Renamed. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1061"'
    127.     Dim str_Renamed(3) As String
    128.     Dim x As Short
    129.    
    130.     Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
    131.         Text1.Text = str_Renamed(x)
    132.         x = x + 1
    133.         x = x Mod 4
    134.     End Sub
    135.    
    136.     Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
    137.         str_Renamed(0) = "David "
    138.         str_Renamed(1) = "is "
    139.         str_Renamed(2) = "the "
    140.         str_Renamed(3) = "Best!"
    141.         Text1.Enabled = False
    142.     End Sub
    143. End Class

    Runs exactly the same way.

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: newbie vb question

    That is totally sick looking code logic by the wizard. Yet another example of why not to use the upgrade wizard.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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