There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Mass adding/re-valuing


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
asbo's Avatar
Senior Member with 510 posts.
 
Join Date: Sep 2001
Location: who really knows anymore?
Experience: Advanced
07-Jul-2002, 05:06 PM #1
Mass adding/re-valuing
Ok, I have 90-some textboxes and I have to add all the .Text values, which will be integers, together into an interger variable for later usage.

In another instance, I have a button to reset all of the values to "0", but do i have have to do this individually, or could I use another command.

In both situations, I believe I could use a loop, but I have no idea how to use them, much less do this...

Can anyone help?

::Leader of dumb question on the Dev board ::
__________________
·· ħþø ··
-----
- User Friendly by Illiad -
TimCottee's Avatar
Senior Member with 186 posts.
 
Join Date: Oct 2001
Location: Southampton, England
09-Jul-2002, 07:52 AM #2
I assume we are talking VB here?

Code:
Private Sub cmdAddEmUp_Click()
  MsgBox AddUp()
End Sub

Private Sub cmdReset_Click()
  Dim ctrlReset As Control
  For Each ctrlReset In Controls
    If TypeOf ctrlReset Is TextBox Then
      ctrlReset.Text = ""
    End If
  Next
End Sub

Private Function AddUp() As Integer
  Dim ctrlAdd As Control
  For Each ctrlAdd In Controls
    If TypeOf ctrlAdd Is TextBox Then
      AddUp = AddUp + CInt(ctrlAdd.text)
    End If
  Next
End Function
asbo's Avatar
Senior Member with 510 posts.
 
Join Date: Sep 2001
Location: who really knows anymore?
Experience: Advanced
09-Jul-2002, 09:31 AM #3
I don't quite understand the syntax (that could take a couple weeks ), but thanks nonetheless.
TimCottee's Avatar
Senior Member with 186 posts.
 
Join Date: Oct 2001
Location: Southampton, England
09-Jul-2002, 09:43 AM #4
To explain what is going on, every form has a collection which is the .Controls collection, every control that is on the form whether added at design time or dynamically at runtime is a member of this collection. Therefore we can use iterative methods (For Each .. Of ..) to traverse this collection. Because there is a default object type "Control" which can be used to reference a control of any type we use that as the iterator, we then test that the control is actualy of type "TextBox" and if it is then we can refer to the object we are iterating with as if it were the real textbox on the form.

That may or may not help explain things a little as it sounds much more complicated than it really is.
__________________
TimCottee
I know a little about a lot of things and a lot about very little.

Brainbench MVP For Visual Basic
http://www.brainbench.com

MCP, MCSD, MCDBA, CPIM

Visit http://flame2006.org.uk or http://www.timcotte.tk
Snake~eyes's Avatar
Senior Member with 639 posts.
 
Join Date: Apr 2002
09-Jul-2002, 10:00 AM #5
Tim, how do you know so much about VB? Are you self taught?

-Snake
TimCottee's Avatar
Senior Member with 186 posts.
 
Join Date: Oct 2001
Location: Southampton, England
09-Jul-2002, 10:28 AM #6
I am indeed 100% self-taught, though I have learnt as much from participating in sites such as this over the years as I have from experimenting myself.

I am a devout non-reader of manuals so much prefer to figure things out myself and ask for help only when that fails (which it doesn't that often these days).

I pretty much don't do anything other than VB though I do dabble a bit in HTML and a few other languages and have taken on quite a wide variety of projects both within my company and outside so have had a whole range of issues to resolve.
__________________
TimCottee
I know a little about a lot of things and a lot about very little.

Brainbench MVP For Visual Basic
http://www.brainbench.com

MCP, MCSD, MCDBA, CPIM

Visit http://flame2006.org.uk or http://www.timcotte.tk
Snake~eyes's Avatar
Senior Member with 639 posts.
 
Join Date: Apr 2002
09-Jul-2002, 09:03 PM #7
Quote:
Originally posted by TimCottee:
I am a devout non-reader of manuals
Yah, I hate reading manuals and stuff.

Im self taught myself on PHP and HTML but C++ and Visual Basic I have were taught to me.

Since I know those I can usually read what a javascript or a asp page does, just from knowning C++ and PHP.

If I learned the syntax of those then I could write them easily too.

Ive just never had any reason to learn asp or javascvript so I don't bother.

Usually the only code I write is web based stuff, I haven't written a non web proggy in quite a while. I never really had the reason too.
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 11:52 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.