Wrox Programmer Forums
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 6th, 2005, 06:06 PM
Authorized User
 
Join Date: Jun 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help with code.

Doing a project and need some help please with codeing. here is what it looks like.
http://img300.imageshack.us/img300/5946/code4du.jpg

And here is the code I have.

Dim Names() As String
Dim intArrayCounter As Integer

Private Sub cmdAdd_Click()
Dim i As Integer
On Error GoTo ErrMsg
'save upper limit to array names()
intArrayCount = UBound(Names)

'Resize Names() if latest element holds a value
If Names(UBound(Names)) <> "" Then
    intArrayCount = intArrayCount + 1
    MsgBox "Incresing the Array Size"
    ReDim Preserve Names(intArrayCount) As String
    End If

    'Scroll through array until empty element is found
    For i = 0 To UBound(Names)
    If Names(i) = "" Then
    'validate textbox has content
If txtName.Text <> "" Then
Names(i) = txtName.Text
txtName.Text = ""
txtName.SetFocus
Call cmdPrint_Click
Exit For
Else
    Err.Raise 10999
End If
End If
Next

End Sub

ErrMsg
    MsgBox "Please enter a name in the " & vbCrLf & " appropraite space provided." & vbCrLf & vbCrLf & _
            "The following error occured: vbCrLf & Err.Description, vbExclamation + vbOKOnly, vbCrLf & Error Message: Error Number(" & Err.Number & ")"
Exit Sub
End Sub

Private Sub cmdClear_Click()
Dim Names(0) As String
frmArrayDisplay.Cls
txtName.SetFocus
End Sub

Private Sub cmdExit_Click()
    Exit Sub
End Sub

Private Sub cmdPrint_Click()
Dim i As Integer
frmArrayDisplay.Cls
    If UBound(Names) <= 25 Then
        For i = 0 To UBound(Names)
            If Names(i) <> "" Then
                If i < 9 Then
                If i < 1 Then
                    frmArrayDisplay.Print " "
                End If
                    frmArrayDisplay.Print " " & " " & i + 1&; ". " & Names(i)
                Else
                    frmArrayDisplay.Print " " & i + 1&; ". " & Names(i)
                End If
            End If
        Next
    Else
        ReDim Preserve Names(25)
        MsgBox " No more than 26 names can be entered " & vbCrLf & _
            "Because the form will not hold the list." & vbCrLf & "A mazimum of 26 names can be entered.", vbExclamation = vbOKOnly, "Error Message"

    End If
    txtName = SetFocus

End Sub

Private Sub Form_Activate()
    Unload frmArrayDisplay
    txtName.Text = ""
    txtName.SetFocus
End Sub

Private Sub form_Load()
    ReDim Names(0) As String
End Sub



Private Sub Form_resize()
    frmArrayDisplay.Width = 30
    frmArrayDisplay.Height = 58
End Sub

Private Sub txtName_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        Call cmdAdd_Click
    End If
End Sub
 
Old July 6th, 2005, 11:02 PM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 221
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello

Could you please explain what are you trying to
achive with this. I have seen code and the image.
As of me, it is very easy to do it. (Adding items and
printing them). Seeing to your code and Image, i am
a lot confused why have you taken such a long process
of coding.

Please explain clearly what exactly you want and what
controls that you want to use in you project to
achive this.

With Regards,
Raghavendra Mudugal
 
Old July 7th, 2005, 05:20 PM
Authorized User
 
Join Date: Jun 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

When you put a name in the text box it puts it in the Box. And some of the code is correct but some of it does not work. The Add Item is supposed to add what ever you type in. The Clear clears the list and the print list re-shows the list of items I had previously put on there if I had cleared the list I think.



 
Old July 9th, 2005, 05:00 PM
Authorized User
 
Join Date: Jun 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Anyone?

 
Old July 11th, 2005, 08:29 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

can you please be more specific... what kind of error do you have??

what's your problems????

we dont have your form, we dont have your project, we can help you with specific problems, no debbuging your code for you...

be more specific and you will receive and answer...

HTH

Gonzalo
 
Old July 11th, 2005, 04:17 PM
Authorized User
 
Join Date: Jun 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is the error i get.
http://img159.echo.cx/img159/2739/error15xx.jpg
When i click debug i get this.
http://img159.imageshack.us/img159/8614/error114ln.jpg

 
Old July 12th, 2005, 08:19 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

could it be that your textbox is not enable??

usually you have that problem with controls when they can get the focus...

take out that line...

you can put the focus directly to the control if you put his taborder to 0...

HTH

Gonzalo
 
Old July 12th, 2005, 01:43 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In the Activate event the textBox is not visible yet, thus you cannot set the focus to it. Always put On Error... when you use SetFocus.
As Gonzalo says, set the tabIndex property correctly for all your controls at design time.
Marco





Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent:hard disk serial code and vb code ivanlaw Pro VB 6 0 July 25th, 2007 04:05 AM
VB: .Exe file, serial code and activation code ivanlaw Pro VB 6 8 July 6th, 2007 05:44 AM
code clinic - Why wont example asp code work? jardbf Classic ASP Basics 3 April 27th, 2006 06:22 PM
Writing Client Side Script from Code-Behind code sajid_pk Classic ASP Databases 1 January 18th, 2005 12:53 AM
disable forum code within [code] blocks? nikolai Forum and Wrox.com Feedback 0 October 23rd, 2003 07:52 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.