<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Visual Basic Error in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/visual-basic-error/m-p/1238141#M46497</link>
    <description>There is one more problem, I did write the code in VBA and changed it to work in VB but now when I select the KeyPress option from the menu belonging to the correct textbox in VB I still get the VBA code...how is this possible?</description>
    <pubDate>Tue, 01 Feb 2005 23:10:11 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2005-02-01T23:10:11Z</dc:date>
    <item>
      <title>Visual Basic Error</title>
      <link>https://forums.autodesk.com/t5/vba-forum/visual-basic-error/m-p/1238139#M46495</link>
      <description>I have written the following code to work in VB6.0 and at first everything works fine, after saving and re-opening the file I keep getting this error message:&lt;BR /&gt;
&lt;BR /&gt;
"User-defined type not defined"&lt;BR /&gt;
&lt;BR /&gt;
This is the code:&lt;BR /&gt;
&lt;BR /&gt;
Private Sub TextBoxCatPrijs_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)&lt;BR /&gt;
&lt;BR /&gt;
'Staat alleen de invoer van getallen en een aantal noodzakelijke tekens toe&lt;BR /&gt;
&lt;BR /&gt;
If KeyAscii = 44 Or KeyAscii = 45 Or KeyAscii = 46 Then Exit Sub Else&lt;BR /&gt;
    &lt;BR /&gt;
    If KeyAscii &amp;lt; 48 Or KeyAscii &amp;gt; 57 Then&lt;BR /&gt;
        KeyAscii = 0&lt;BR /&gt;
        Beep&lt;BR /&gt;
        Else&lt;BR /&gt;
    End If&lt;BR /&gt;
    &lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
There are about 20 textboxes to which I want to add this code. Can anyone help me with this problem?&lt;BR /&gt;
&lt;BR /&gt;
Thanks allready</description>
      <pubDate>Tue, 01 Feb 2005 15:39:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/visual-basic-error/m-p/1238139#M46495</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-02-01T15:39:15Z</dc:date>
    </item>
    <item>
      <title>Re: Visual Basic Error</title>
      <link>https://forums.autodesk.com/t5/vba-forum/visual-basic-error/m-p/1238140#M46496</link>
      <description>I'm wondering if you wrote that in vba and tried to run it in vb?
The syntax is not exactly the same.

'VBA SYNTAX
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
  KeyAscii = DecimalOnly(TextBox1, KeyAscii)
End Sub


'VB SYNTAX
Private Sub TextBox1_Keypress(KeyAscii As Integer)
  KeyAscii = DecimalOnly(TextBox1, KeyAscii)
End Sub

If you want to apply it to several textboxes you may want to wrap it in a
sub that takes a textbox as an argument so you only have to write it once
then pass each textbox to it as arg.

eg for examples above
Function DecimalOnly(ByRef objCtl As Object, ByVal iIndex As Integer) As
Integer

  Dim rtn As Integer
    Select Case iIndex
    Case 8 ' backspace/delete
        ' always allow this key
        rtn = iIndex
    Case 48 To 57 ' Asc("0") to Asc("9")
        ' allow these characters
        rtn = iIndex
    Case Asc(".")
        'only allow one decimal point
        If InStr(objCtl.Text, ".") = 0 Then
            'allow decimal
            rtn = iIndex
        Else
            rtn = 0
        End If

    Case Else
        ' reject these characters
        rtn = 0
    End Select
    DecimalOnly = rtn
End Function

hth
Mark

"SeriouslyDutch" &lt;NOSPAM&gt; wrote in message
news:14275034.1107272386124.JavaMail.jive@jiveforum2.autodesk.com...
&amp;gt; I have written the following code to work in VB6.0 and at first everything
works fine, after saving and re-opening the file I keep getting this error
message:
&amp;gt;
&amp;gt; "User-defined type not defined"
&amp;gt;
&amp;gt; This is the code:
&amp;gt;
&amp;gt; Private Sub TextBoxCatPrijs_KeyPress(ByVal KeyAscii As
MSForms.ReturnInteger)
&amp;gt;
&amp;gt; 'Staat alleen de invoer van getallen en een aantal noodzakelijke tekens
toe
&amp;gt;
&amp;gt; If KeyAscii = 44 Or KeyAscii = 45 Or KeyAscii = 46 Then Exit Sub Else
&amp;gt;
&amp;gt;     If KeyAscii &amp;lt; 48 Or KeyAscii &amp;gt; 57 Then
&amp;gt;         KeyAscii = 0
&amp;gt;         Beep
&amp;gt;         Else
&amp;gt;     End If
&amp;gt;
&amp;gt; End Sub
&amp;gt;
&amp;gt; There are about 20 textboxes to which I want to add this code. Can anyone
help me with this problem?
&amp;gt;
&amp;gt; Thanks allready&lt;/NOSPAM&gt;</description>
      <pubDate>Tue, 01 Feb 2005 18:31:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/visual-basic-error/m-p/1238140#M46496</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-02-01T18:31:50Z</dc:date>
    </item>
    <item>
      <title>Re: Visual Basic Error</title>
      <link>https://forums.autodesk.com/t5/vba-forum/visual-basic-error/m-p/1238141#M46497</link>
      <description>There is one more problem, I did write the code in VBA and changed it to work in VB but now when I select the KeyPress option from the menu belonging to the correct textbox in VB I still get the VBA code...how is this possible?</description>
      <pubDate>Tue, 01 Feb 2005 23:10:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/visual-basic-error/m-p/1238141#M46497</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-02-01T23:10:11Z</dc:date>
    </item>
    <item>
      <title>Re: Visual Basic Error</title>
      <link>https://forums.autodesk.com/t5/vba-forum/visual-basic-error/m-p/1238142#M46498</link>
      <description>"SeriouslyDutch" &lt;NOSPAM&gt; wrote in message
news:21173997.1107299441964.JavaMail.jive@jiveforum2.autodesk.com...
&amp;gt; There is one more problem, I did write the code in VBA and changed it to
work in VB but now when I select the KeyPress option from the menu belonging
to the correct textbox in VB I still get the VBA code...how is this
possible?

Sorry, I'm not understanding.
What do you mean by "when I select the KeyPress option from the menu
belonging to the correct textbox "
What menu are you talking about?

If you are in vb6, place a textbox on an empty form, double click in the
textbox, the code window pops up.
If you go to the top right drop down box and select Keypress,
a sub is created with this format:
Private Sub Text1_KeyPress(KeyAscii As Integer)

End Sub

that is the syntax you need in vb.

Now what do you mean by "menu belonging to the textbox"?&lt;/NOSPAM&gt;</description>
      <pubDate>Tue, 01 Feb 2005 23:46:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/visual-basic-error/m-p/1238142#M46498</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-02-01T23:46:06Z</dc:date>
    </item>
    <item>
      <title>Re: Visual Basic Error</title>
      <link>https://forums.autodesk.com/t5/vba-forum/visual-basic-error/m-p/1238143#M46499</link>
      <description>The method you described is exactly what I did. But when I select that drop down menu in VB 6.0 I get the wrong code, the code I should get in VBA (ByVal KeyAscii as MSform....), maybe because the form was originaly designed in VBA...&lt;BR /&gt;
&lt;BR /&gt;
Is there a way to solve this problem?</description>
      <pubDate>Wed, 02 Feb 2005 00:04:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/visual-basic-error/m-p/1238143#M46499</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-02-02T00:04:52Z</dc:date>
    </item>
    <item>
      <title>Re: Visual Basic Error</title>
      <link>https://forums.autodesk.com/t5/vba-forum/visual-basic-error/m-p/1238144#M46500</link>
      <description>SeriouslyDutch wrote:
&amp;gt; The method you described is exactly what I did. But when I select that drop down menu in VB 6.0 I get the wrong code, the code I should get in VBA (ByVal KeyAscii as MSform....), maybe because the form was originaly designed in VBA...

VBA forms are not direct counterparts to VB forms. One solution is to 
redesign the form in VB and copy your code across, making adjustments 
for differrences in types such as the one you've encountered.

-- 
There are 10 kinds of people: those who understand binary and those who 
don't.</description>
      <pubDate>Wed, 02 Feb 2005 00:23:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/visual-basic-error/m-p/1238144#M46500</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-02-02T00:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: Visual Basic Error</title>
      <link>https://forums.autodesk.com/t5/vba-forum/visual-basic-error/m-p/1238145#M46501</link>
      <description>When you select the object and procedure from the drop-down lists at the top of the code pane VB searches for a procedure with the correct name but doesn't check it's signature - that only happens at compile-time.  If a procedure with the correct name is not found, an empty one will be created - with the correct signature.  You can comment out the incorrect one, select it from the drop-down to recreate it, and move your code into the new procedure.</description>
      <pubDate>Wed, 02 Feb 2005 12:04:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/visual-basic-error/m-p/1238145#M46501</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2005-02-02T12:04:35Z</dc:date>
    </item>
  </channel>
</rss>

