Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA 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 February 27th, 2007, 07:05 PM
Registered User
 
Join Date: Feb 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default text box programming

Hi, I hope you can help.

I'm very new to VBA. I 'm trying to display a string of digits in a text box, but I'm only able to display one digit at the time by doing:
Code:
TextBox1 = 6
.

Any help is dearly appreciated.

 
Old February 28th, 2007, 12:07 AM
Registered User
 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Vinny
      If u want to display the digits in textbox,u can directly put
  Textbox1.text = 4545

or

u can put as a string

textbox1.text = "33434"

hope this will get u clear.if u have further clarification u can really ask me

bye takecare

Sathish
 
Old February 28th, 2007, 05:23 AM
Registered User
 
Join Date: Feb 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank you for your reply,
see i'm actualy trying to enter digits in the text box using the commanb button that i created for the calculator.
exple: if someone push command button 2, it should display 2, then if someone pushes 5 (before pushing any operator sign), it should display 25...
 
Old February 28th, 2007, 05:59 AM
Registered User
 
Join Date: Feb 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I would have liked to attach what copy of what I'm trying to do, but there's no way to attach a document !
hey sathishr do you have an email where I can send you an xl sheet of what i m doing?
 
Old February 28th, 2007, 06:04 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

When you assign a value to the text box , the last value goes off

all you need to do is

Sub cmdFive_Click
 Textbox1.text = Textbox1.text & "5"
end sub

Sub cmdSix_Click
 Textbox1.text = Textbox1.text & "6"
end sub

etc

if you nave some cancel or 'C'

Sub cmdFive_Click
 Textbox1.text = ""

end sub

Cheers
Shasur

http://www.vbadud.blogspot.com
 
Old February 28th, 2007, 06:32 AM
Registered User
 
Join Date: Feb 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Great Shasur that helped a lot!
Anyone knows if there is a particular function I could use to have the user be able to choose to enter the operator sign by either pushing the button on the calculator or just using the signs (+, -, *, /) on the keyboard?

 
Old February 28th, 2007, 07:30 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

'Hi Vinny here is how you have to do. Trap the KeyPress event.
' Do not accept any characters other than numerals or operators.. you can include text if you want



Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

    Dim myStr As String


    If 48 > KeyAscii < 57 Then ' numbers
        ' Accept the character
    ElseIf KeyAscii = 42 Then ' * character
        ' move the str for later processing
        myStr = TextBox1.Text
        TextBox1.Text = "+"
    ElseIf KeyAscii = 43 Then '+

    ElseIf KeyAscii = 45 Then '-

    ElseIf KeyAscii = 47 Then '/

    ElseIf KeyAscii = 61 Then '= char
        ' process the result
        ' do the operation and show it on screen


    Else
        ' Cancel the text box entry
    End If

End Sub

Here you have the ascci codes


Asc Value
1 
2 
3 
4 
5 
6 
7 
8 
9 " "
10 "
"
11
12
13 "
"
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32
33 !
34 "
35 #
36 $
37 %
38 &
39
40 (
41 )
42 *
43 +
44 ,
45 -
46 .
47 /
48 0
49 1
50 2
51 3
52 4
53 5
54 6
55 7
56 8
57 9
58 :
59 ;
60 <
61 =
62 >
63 ?
64 @
65 A
66 B
67 C
68 D
69 E
70 F
71 G
72 H
73 I
74 J
75 K
76 L
77 M
78 N
79 O
80 P
81 Q
82 R
83 S
84 T
85 U
86 V
87 W
88 X
89 Y
90 Z
91 [
92 93 ]
94 ^
95 _
96 `
97 a
98 b
99 c
100 d
101 e
102 f
103 g
104 h
105 i
106 j
107 k
108 l
109 m
110 n
111 o
112 p
113 q
114 r
115 s
116 t
117 u
118 v
119 w
120 x
121 y
122 z
123 {
124 |
125 }
126 ~
127 
128 €
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161 ¡
162 ¢
163 £
164 ¤
165 ¥
166 ¦
167 §
168 ¨
169 ©
170 ª
171 «
172 ¬
173 ­
174 ®
175 ¯
176 °
177 ±
178 ²
179 ³
180 ´
181 µ
182 ¶
183 ·
184 ¸
185 ¹
186 º
187 »
188 ¼
189 ½
190 ¾
191 ¿
192 À
193 Á
194 Â
195 Ã
196 Ä
197 Å
198 Æ
199 Ç
200 È
201 É
202 Ê
203 Ë
204 Ì
205 Í
206 Î
207 Ï
208 Ð
209 Ñ
210 Ò
211 Ó
212 Ô
213 Õ
214 Ö
215 ×
216 Ø
217 Ù
218 Ú
219 Û
220 Ü
221 Ý
222 Þ
223 ß
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253 ý
254 þ
255 ÿ



http://www.vbadud.blogspot.com
 
Old February 28th, 2007, 11:45 AM
Registered User
 
Join Date: Feb 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanx again Shashur. I'm now trying to code the factorielle. would anyone please
take a look at my code and tell me what's wrong with it, it gives
me a "Run-time" error '424', Object required"

Private Sub CommandButtonfactorielle_Click()
Dim data As Long
Dim rdata As Long

Set TextBox1.Copy = rdata

counter = rdata
Do While counter > 1
counter = counter - 1
data = rdata * counter
Exit Do
Loop
Set TextBox1.Value = data

End Sub

 
Old February 28th, 2007, 11:54 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Vinny

Set command is used for objects you create, like the workbook etc

Textbox doesn't need that

Replace

Set TextBox1.Value = data

with

TextBox1.Value = data

Should work

Cheers
Shasur:)


http://www.vbadud.blogspot.com
 
Old February 28th, 2007, 01:13 PM
Registered User
 
Join Date: Feb 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I did, it gives me the same error!!!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Grab Values From List Box into Text Box phungleon VB How-To 2 June 19th, 2008 10:33 PM
Count in combo box(display results in text box) mboyisis Access 4 April 4th, 2008 07:08 AM
Extract text from text file & put in dropdown box tsukey Beginning PHP 5 July 20th, 2004 09:49 PM
Rich Text Box vs Text Box snowy0 VB.NET 2002/2003 Basics 1 February 17th, 2004 02:11 PM
Search using drop down list box and a text box tcasp Classic ASP Basics 1 July 31st, 2003 02:58 PM





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