Print values dynamically on a form

I have a form that needs to display values from an array on the form; how do 
I achieve the following?

If item count in array is < 20 then print

Val1    Val2   
Val3    Val4   
Val5    Val6
and so on   

If items in array is > 20 then print

Val1    Val2   Val3
Val4    Val5   Val6
Val7    Val8   Val9
and so on

The following code works fine and prints values in two columns butI need to 
modified it to print in three columns if nItemsCount > 20

for i=1 to nItemsCount

  If i Mod 2 Then
    nX = nX * 25
    nY = nY - 15
  End If

  myVal.Name = "myVal" & i
  myVal.Text = sLabel
  myVal.Location = New Point(nX, nY + 15)
  Controls.Add(myTextBoxLabel)
Next
0
Utf
2/24/2010 8:31:01 PM
dotnet.languages.vb 830 articles. 0 followers. Follow

2 Replies
783 Views

Similar Articles

[PageSpeed] 28

On 2/24/2010 3:31 PM, Rick wrote:
> I have a form that needs to display values from an array on the form; how do
> I achieve the following?
>
> If item count in array is<  20 then print
>
> Val1    Val2
> Val3    Val4
> Val5    Val6
> and so on
>
> If items in array is>  20 then print
>
> Val1    Val2   Val3
> Val4    Val5   Val6
> Val7    Val8   Val9
> and so on
>
> The following code works fine and prints values in two columns butI need to
> modified it to print in three columns if nItemsCount>  20
>
> for i=1 to nItemsCount
>
>    If i Mod 2 Then
>      nX = nX * 25
>      nY = nY - 15
>    End If
>
>    myVal.Name = "myVal"&  i
>    myVal.Text = sLabel
>    myVal.Location = New Point(nX, nY + 15)
>    Controls.Add(myTextBoxLabel)
> Next

I don't see your code as working the way you believe it is.  That said, 
here is how I would do what you seem to want:

         Dim nItemsCount As Integer = 22 ' or some other value...
         Dim nx As Integer = 10
         Dim ny As Integer = 10

         Dim nc As Integer = 2
         If (nItemsCount > 20) Then nc = 3

         For i = 1 To nItemsCount
             Dim myVal As Label = New Label()

             myVal.Name = "myVal" & i
             myVal.Text = myVal.Name
             myVal.Location = New Point(nx, ny)

             nx = nx + myVal.Width + 10

             If (i Mod nc = 0) Then
                 nx = 10
                 ny = ny + 25
             End If

             Controls.Add(myVal)
         Next


-- 
Mike
0
Family
2/24/2010 10:16:09 PM
Thanks

"Family Tree Mike" wrote:

> On 2/24/2010 3:31 PM, Rick wrote:
> > I have a form that needs to display values from an array on the form; how do
> > I achieve the following?
> >
> > If item count in array is<  20 then print
> >
> > Val1    Val2
> > Val3    Val4
> > Val5    Val6
> > and so on
> >
> > If items in array is>  20 then print
> >
> > Val1    Val2   Val3
> > Val4    Val5   Val6
> > Val7    Val8   Val9
> > and so on
> >
> > The following code works fine and prints values in two columns butI need to
> > modified it to print in three columns if nItemsCount>  20
> >
> > for i=1 to nItemsCount
> >
> >    If i Mod 2 Then
> >      nX = nX * 25
> >      nY = nY - 15
> >    End If
> >
> >    myVal.Name = "myVal"&  i
> >    myVal.Text = sLabel
> >    myVal.Location = New Point(nX, nY + 15)
> >    Controls.Add(myTextBoxLabel)
> > Next
> 
> I don't see your code as working the way you believe it is.  That said, 
> here is how I would do what you seem to want:
> 
>          Dim nItemsCount As Integer = 22 ' or some other value...
>          Dim nx As Integer = 10
>          Dim ny As Integer = 10
> 
>          Dim nc As Integer = 2
>          If (nItemsCount > 20) Then nc = 3
> 
>          For i = 1 To nItemsCount
>              Dim myVal As Label = New Label()
> 
>              myVal.Name = "myVal" & i
>              myVal.Text = myVal.Name
>              myVal.Location = New Point(nx, ny)
> 
>              nx = nx + myVal.Width + 10
> 
>              If (i Mod nc = 0) Then
>                  nx = 10
>                  ny = ny + 25
>              End If
> 
>              Controls.Add(myVal)
>          Next
> 
> 
> -- 
> Mike
> .
> 
0
Utf
2/25/2010 12:36:02 AM
Reply:

Similar Artilces:

Event of changing the grid-cell value.
Hello. In VB.NET 2008. I have dataGridView. Which event occurs when changing data row value. (Not all the times I am changing the value via the dataGridView directly. There are also values that are changed directly via the datatable object. I need a general method, please. dataGridView is connected to BindingSource). Thanks :) In general you should avoid changing values using a datagridview, that is the client area, you would use the object which is the datasource of the bindingsource. I understand from your other messages it is a datatable but it can be any collection. ...

Refresh Form after custom action
I set a value of an account through custom application, how can I refresh the account window from which I clicked the toolbarbutton I've heard of a sort of callback ? window.opener? CRM itself manages, that you can open a record only once. how? TIA Stefan Try window.opener.location.reload() On 18 Oct 2004 10:32:42 -0700, s.rauchegger@gmx.at (Stefan Rauchegger) wrote: >I set a value of an account through custom application, how can I >refresh the account window from which I clicked the toolbarbutton > >I've heard of a sort of callback ? window.opener? > >CRM...

Hide subforms control from main forms control
I have no idea how to hide some controls in my subform if value in a textbox in main form is >1 or =1.I can't write a code. Please help. Ciao New_Access wrote: > I have no idea how to hide some controls in my subform > if value in a textbox in main form is >1 or =1.I can't write a code. > Please help. Private sub form_current() if youControlName => "1" then forms!NameForm!SubForm.form.YouControlName.visible = false end if end sub -- Ciao Geppo geppo, why does access think my FormName is a fieldname. "geppo" <ccc@tin.it.inva...

IMPORTING A FORM
I have to fill out a payroll form each week for each contractor showing gross, deductions, net, hours and wages for each one. I have a form in formtoolv5 that I go in and edit. My quickbooks will download the payroll information I need into excel, but is there a way I can import this form and it would put things in the proper columns? I can not figure out how to do it in excel. I am very new to excel and all I have managed to accomplish is a headache. Any info would be helpful. I'm not familiar with FormTool v5. Where can we find out some more about it? Part of Quickbooks? Is ...

Forms through outlook.
I have been trying to develop a form through Outlook. That part I have done. Now what I'm trying to do is sent this form to the units in my battalion as a reoccurring task. I would like the form to be sent to them and make it were all they have to do is answer some questions and fill out an issue block then just click a "SEND" button. I would like the "SEND" button to send the form through outlook to my e-mail inbox. Right now if I click the "send" button the address box opens and in the "TO" box there is a date. Even if I delete the date a...

Forms and Subforms issues.
Hello everyone! I need some major assistance on a personal project. I've been stuck on the whole subforms issue (not that I don't know how they work). In any event, I've been creating a personal DVD collectoin database, and have done fairly decent until now. I have a main form that I want to use and display the same information in two different ways. On the left side of the form, I want to use a query (subform) to display a list of all the movies that I do own. I on the right side of the form, I want to have another subform listed to detail all the information of the selected ...

Filtering Via Form, and then Export
Hi: I have a database 'query' that has about 200K rows of data. My user population, and any given time, is interested in working with (charting, excel'ing, powerpointing, etc) just a small subset of the data (for example, all rows of data for a given month, to work on month end reports (the file contains ~2 years of data). Each of these users sends me requests for excel files (sometimes access table data creation, as well) for their specific needs, based upon a fairly limited set of what I call requirements and/or filters. I envision a "form" that they could us...

Listbox controlling Sub-form
I have a listbox that is populated from a sub query (qyListFEA). I have set the subform's LinkMasterField and LinkChildField to this listbox. The list box contains 3 columns (Project Name, Project Number and Iteration). When I select let's say Wheel 1, 5214, 1C, the subform only shows the Wheel 1 at iteration 1. How can I get the data to synchronize so that if I select Wheel 1 at iteration 1c or 2, etc. I can get the correct record to show? Note: the sub query "qyListFEA" is based upon "qyFEA" which is where I need the actual data from. If I use the master...

Custom scroll bars skipping values
I have added a few custom scroll bars that have an incremental change of (1) and range from 1 to 200. Sometimes they seem to have a mind of their own and take off like they are ignoring the increment value of (1) and jump 5, 10, or 20 increments. Any thoughts? ...

Using value from Dataset 2 in calculation in Dataset 1
Hello- Bumping in to an exception that I cant seem to get around. Report has two datasets. I need to use a value that dataset2 returns. (Dataset 2 is just a stored proc that returns a single value.) Dataset1 has a calculated field that needs to reduce the value in a field by the value that is returned from dataset2. I think the way to do this is to reference the textbox.value that holds the value from dataset2: calculated field = field_from_dataset1.value - sum(ReportItems! credit.value) where ReportItems!credit.value is the textbox that has the value returned from DS2. ...

Portfolio market value report over time
The Portfolio Manager shows a Market Value at the bottom of the screen. I can change the "As of" date near the top of the screen and the Market Value will show the value as of that date. I would love to run a report that shows the Market Value for a user specified range of dates, with a selectable granularity of day/week/month/year, etc. Is there such a report? In microsoft.public.money, cgunther wrote: >The Portfolio Manager shows a Market Value at the bottom of the screen. I >can change the "As of" date near the top of the screen and the Market Value >...

Printing Multiple Ranges
I have a worksheet that has 16 different ranges (entitled Page1, Page2, ..., Page16). I want to print each page in its correct order. So I go to Page Setup and make the print area be "Page1, Page2, Page3" and so on. But instead of keeping the ranges in that order, it converts them to cells so the print_area becomes J139:ER193. This wouldn't be a problem, except that the pages aren't in the correct order in the worksheet, so when I print I get page 6, 7, 8, 13, 1.... So I ask, is there a simple way to do this in excel? I also tried to write a macro to do this, a...

VBA Open a Form upon Startup
I have other users, using an excel spreadsheet that I have created, bu when they first open this spreadsheet I want a message box / Form t appear straight away. I have already created the form. Any help appreciated. Thank -- Message posted from http://www.ExcelForum.com In VBA double click on "ThisWorkbook" Change the dropdown box at the top from "(General)" to "Workbook" Change the other dropdown to "Open" Then: Private Sub Workbook_Open() UserForm1.Show End Sub Change userform1 to whatever your form is Alternitivly, you could always use msg...

print from spreadsheet
I have a speadsheet with a b c d e f g h i columns and i just want to print a c g h how can I do that on one page?? -- jladik ----------------------------------------------------------------------- jladika's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=910 View this thread: http://www.excelforum.com/showthread.php?threadid=38726 Hide the unwanted columns>print -- Don Guillett SalesAid Software donaldb@281.com "jladika" <jladika.1s68mq_1121364463.505@excelforum-nospam.com> wrote in message news:jladika.1s68mq_1121364463.505@...

How do I print up different labels in Publisher on the same page?
It can't figure out how to change the text for each label. In print preview it shows all the same text on every label and I need different text on each label...help please!! If you are using merge, the print preview is a bug in the program. Do a sample from print (print two rows as a test) -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Kittymayo1" <Kittymayo1@discussions.microsoft.com> wrote in message news:9C273930-65AD-46C2-856A-FCEDC31ACB4F@microsoft.com... > It can't figure out how to change the te...

Formulas and numerical value of answers
Hi all, Whenever we have a formula, is it possible to convert the formulas (of different cells of an entire worksheet) into the actual values? e.g. Formula of C3 = C1 + C2, (C1 = 1 ; C2 = 1) so instead of seeing C1 + C2 when C3 is highlighted, you will see the numerical answer 2. Thanks in advance. -- olitong ------------------------------------------------------------------------ olitong's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=29805 View this thread: http://www.excelforum.com/showthread.php?threadid=495130 Select the cell(s) you want this to happ...

Having problems printing a single report
Hi This is the code I have entered in the event procedure to print a single record. Unfortunately, it's not working. How do I fix this code: Private Sub Print_this_record_Click() Dim strDocName As String Dim strWhere As String strDocName = "R1-1 GPS_GeneralInfo" strWhere = "[StudentID]=" & Me!StudentID DoCmd.OpenReport strDocName, acPreview, , strWhere End Sub I need to print out one StudentID for the report R1-1 GPS_GeneralInfo. When I click on the button, a popup box with the Student CG2002 appears. Thanks for your ...

D-Link DP-301U print server will not print from Outlook, OE, or Firefox
Hi, folks. We've got a home network here with an XP machine and an Apple Quad PowerPC. We hooked up a D-Link DP-301U print server a couple weeks ago with our D-Link DL-624 wireless router and were successful at getting it to print anything the Mac sends to the Samnsung ML-1430 laserprinter. The XP machine is a different story: documents sent from Word, Notepad, or IE6 print ok. We can print the printer test page, too. We *CANNOT* print anything from Outlook 2003, OE6, or Firefox. WHAT is the solution to this problem? I disabled 3rd party browser extensions in IE6, but I can't ...

printing #5
Version: v.X Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel Why won't a document with bullets in it print in 10.6? Any line with a bullet in front of it doesn't print rather the printer stops at the first such line and ejects the page On 9/29/09 3:14 PM, in article 59b7d8b0.-1@webcrossing.caR9absDaxw, "altaguy@officeformac.com" <altaguy@officeformac.com> wrote: > Version: v.X > Operating System: Mac OS X 10.6 (Snow Leopard) > Processor: Intel > > Why won't a document with bullets in it print in 10.6? Any line with a bullet > in...

user parameter
Hi. I want to create a query that will alow a user to search only one drug or more drugs depending on user's needs. For instance, a user can see activity for only asprin or he can see activity for asprin and zantac. select drug, username, date from drugactivity where drug = @drug or drug = @drug or drug = @drug or drug = @drug; Is there an easier way to do this? Thanks in advance. Misty -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-queries/200710/1 It all starts with the data ... Please provide more specific information about what the u...

How to prevent totals from doubling in printed report
I accumulate some totals in the Detail format event. WHen I vies the report, these totals are correct, but when I print the report, they are doubled. I now know when printing, Access processes the report twice. Since all of my reports must be able to be viewed as well as printed, how can I use VBA code to skip the accumulation on either the first or the second pass? Also, how can I determine if the report is being Viewed or Printed? Thanks, Rather than using code to get your totals, look at using the Sum function or the running sum feature in your report. Steve santus@...

Make values stay put in established record & reset in new record?
I'm having a problem making the values on a form reset to $0.00 when I go to a new record. Some more info would help us to help you. How are you going to a new record? A button you put on the form? the new record button on the navigation buttons at bottom left of form? What does the value show instead of $0.00 when you go to a new record? Are there any other values that don't reset when you go to a new record? Jeanette Cunningham "Peg" <Peg@discussions.microsoft.com> wrote in message news:B39F82B9-43E2-4B9A-8F9B-C64B46240857@microsoft.com... > I'm having a...

PROBLEM SIZING A TEXT BOX IN A FORM
Access 2007/vista I have a form in which I cannot adjust the text boxes INDIVIDUALLY. I click on a text box and it becomes surrounded by an orange border, indicating it is selected. But when I size it smaller or larger, all the other text boxes in the form move in tandem. I have not encountered this before and am baffled. Ideas? -- William ...

How is borderless printing set?
I just upgraded to Publisher 2003. My previous version of Pub.( '97 ! ) Had no problem with borderless printing with my HP printer. Some reason, after setting print output to borderless, print preview and actual output has a small white border on three edges and a 1/2" white border and the last edge. Any help would be appreciated. Thanks There have been several suggestions offered here. When you do your page setup, select borderless photo paper for the desired stock. Look at the overspray setting. I've had success by changing my publication into an image and using the pri...

Webbot Form question
I have scaled through the questions and still i am no wiser to solving my problem. I am using the forms and have a submit button which i require to go back to my email account. etc Now i do not plan to publish this website i have developed i have used the save as option to convert it to a web page. the file is stored on our server and appears on our desktop, so really it is functioning like a website just not publish via HTTP. Every item works as it should like a web apge however i get this webbot porblem like others. how do i solve the problem if i am not technically pulshling the we...