|
You can use a recursive method to look for the valid combinations.
Make a method that takes a specific block and the space left in the device. Let it combine the block will all combination of smaller blocks. It does that by calling itself for each smaller block that still fits in the device, to find every combination using that block and any smaller block needed. Return the least number of blocks needed to fill the remaining gap.
---
b { font-weight: normal; }
|
|
|
|
|
Thanks, that's a big help. I'll post some code after I compile it.
Thanks again,
Scott Page
"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
( President Ronald Reagan)
|
|
|
|
|
If this is homework (which I'm sure it is), you should probably try it first and post questions if you get stuck. If somebody here does it for you, you lean nothing.
|
|
|
|
|
I work for Lockheed Martin as a Metrologist, this is for personal and work related intrests.
There would be no reason for this message board to exist if it wasn't here to help others out. I give my 110% and rarely ask for 1% in return, all I need is a faster way to build a Gauge Block stack.
Thanks for the post.
"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
( President Ronald Reagan)
-- modified at 16:02 Wednesday 5th April, 2006
|
|
|
|
|
To a certin degree you are correct, yet being a student and with entry level capability I would like to see the code, just to be able to store it in my memory to use at a future date.
|
|
|
|
|
This problem is usually framed in the guise of how to provide the least number of coins in change. See this Google search[^]
I had a thought that the 'greedy algorithm' would be a good choice but it did not find a solution to 2.305. (The greedy algorithm always takes the highest possible amount from the required sum, remainder and so on - almost opposite to the algorithm you proposed.) Maybe a least-spanning tree algorithm is the way to go?
I also note that with the sample set you provided, you cannot make up a stack of 0.06". Is this correct?
...Steve
1. quod erat demonstrandum
2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once
|
|
|
|
|
Thanks for the post,
I am getting closer to my goal, but still no cigar (I mean stack). Below is the function I'm using to build the stack. In answer to you question about the 0.06" height, Block Sets are manufactured to cover nearly all possible heights seen in the manufacturing and Metrology worlds. If a value does not exist, there other methods used to measure those dimensions.
This function gets me as close as 2.203". I tested the function using 2.203" (correct result), 2.205" (still got 2.203"), 2.305" (still got 2.203"). The returned stack has the 0.101", 0.102" and 2" blocks used, so obviously, since I can't use the 0.102" block, I can't cover the last 0.102" of the height.
The Code:
<code>
'This function exists within a custom collection
Public Function GetStack(ByVal height As Decimal) As GageBlockCollection
Me.ClearUsedBlocks()
Dim Stack As New GageBlockCollection
If Me.HasEqualGageBlock(height) Then
Stack.Add(Me.GetEqualGageBlock(height))
Return Stack
Else
Dim PossibleBlocks As New GageBlockCollection
If height >= 1 Then
'Height is greater than 1", so find the block that makes eliminates the inch part
For Each Block As GageBlock In Me
If height - Block.Height > 0 AndAlso height - block.Height < 1 Then
Block.IsUsed = True
PossibleBlocks.Add(block)
height -= Block.Height
End If
Next
End If
'Find all blocks that are less than the remaining Height (the inch part has been removed)
For Each Block As GageBlock In Me
If Not Block.IsUsed AndAlso Block.Height <= height AndAlso Block.Height.ToString.Length = height.ToString.Length Then
If Block.Height = height Then
Stack.Add(Block)
Block.IsUsed = True
For Each B As GageBlock In PossibleBlocks
Stack.Add(B)
Next
Return Stack
Else
Stack.Add(Block)
Block.IsUsed = True
height -= Block.Height
End If
End If
Next
If Not height = 0 Then
For Each Block As GageBlock In PossibleBlocks
If Not Block.IsUsed AndAlso height - block.Height = 0 Then
Stack.Add(Block)
End If
Next
End If
For Each B As GageBlock In PossibleBlocks
Stack.Add(B)
Next
Return Stack
End If
End Function
</code>
"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
( President Ronald Reagan)
|
|
|
|
|
What if you take the remainder after subtracting the units, first div by 2 and check, then 3 and check. With what you have avaiable all you have to make up is a half inch. Just a thought, it's been running around back there all night.
|
|
|
|
|
Thanks to All for your help,
Here is the code that has worked on several target height values passed.
(Not quite sure how this "code" thing works yet)
<br />
'This function exists within a custom collection<br />
Public Function GetStack(ByVal height As Decimal) As GageBlockCollection<br />
Me.ClearUsedBlocks()<br />
Dim Stack As New GageBlockCollection<br />
If Me.HasEqualGageBlock(height) Then<br />
Stack.Add(Me.GetEqualGageBlock(height))<br />
Return Stack<br />
Else<br />
Dim PossibleBlocks As New GageBlockCollection<br />
If height >= 1 Then<br />
'Height is greater than 1", so find the block that makes eliminates the inch part<br />
For Each Block As GageBlock In Me<br />
If height - Block.Height > 0 AndAlso height - block.Height < 1 Then<br />
Block.IsUsed = True<br />
PossibleBlocks.Add(block)<br />
height -= Block.Height<br />
End If<br />
Next<br />
End If<br />
'Find all Blocks that are smaller than height<br />
For Each Block As GageBlock In Me<br />
If Block.Height < height AndAlso Not Block.IsUsed Then<br />
PossibleBlocks.Add(block)<br />
End If<br />
Next<br />
'Find combinations of blocks that are less that height<br />
Dim Done As Boolean = False<br />
For Each Block1 As GageBlock In PossibleBlocks<br />
For Each Block2 As GageBlock In PossibleBlocks<br />
If height - (Block1.Height + Block2.Height) = 0 Then<br />
Block1.IsUsed = True<br />
Block2.IsUsed = True<br />
Stack.Add(Block1)<br />
Stack.Add(Block2)<br />
Done = True<br />
Exit For<br />
End If<br />
Next<br />
If Done Then<br />
Exit For<br />
End If<br />
Next<br />
For Each Block As GageBlock In PossibleBlocks<br />
If Block.IsUsed Then<br />
Stack.Add(block)<br />
End If<br />
Next<br />
Return Stack<br />
End If<br />
End Function<br />
Thanks again,
Scott Page
"Some people spend an entire lifetime wondering if they made a difference. The Marines don't have that problem."
( President Ronald Reagan)
|
|
|
|
|
is there some thing called re dim S as string
i need to redefine string because the fist time this string work as i want but the second time i face some problem in this parameter
so i need to redefine this parameter for each click on button
kilany
|
|
|
|
|
What is it that you are trying to do?
if you just want to change what the string is equal to then
dim s as string
s = "hello"
s = "world"
|
|
|
|
|
you may be having scope issues. if your declaring a local variable in vb
with "Dim", then taht variable is only valid inside that block.
EX
sub main()
thing()
otherthing
end sub
private sub thing()
dim x as string = "Hello"
debug.writeline(x)
end sub
private sub otherthing()
debug.writeline(x) 'This line causes an error.
end sub
the second reference to 'x' causes an error because it was declared within a block.
to declare globals within a class or module,
use :
Private x as string = "Hello"
sub main()
thing()
otherthing()
end sub
private sub thing()
x = "Hello"
debug.writeline(x)
end sub
private sub otherthing()
debug.writeline(x & " Again") 'No error this time
end sub
Globals are just one answer to a scope issue. paramater passage and other techniques exist. you'll learn 'bout 'em sooner or later
Good Luck
hey...slang is the vernacular for the vernacular...wow
|
|
|
|
|
the another application should receive from vb.net enter + B to do some thing
i send string but i cant send those keys as a parameters
enter+B should send as a parameters from vb.net to another application
how i cant do it ?
kilany
|
|
|
|
|
You can use
AppActivate("Title of the application")<br />
SendKeys.Send(Keys.Enter)
Regards,
Chatura Dilan
If at first you don't succeed, try; try again, so that you know
what not to do the next time. The answer is out there.
|
|
|
|
|
I am looking for suggestions on how to accomplish the following;
I am writing an application that display folders (A - Z) in a treeview. When the user clicks on a folder - a list of companies is retrieved from the database to a dataset and then displayed in a listview w/ checkboxes.
Eventually I want to save the checked listview items to a separate database table - when the user clicks on an OK button. A CANCEL button is also available if the user decides not to proceed.
The issue that I am having is I am not sure what method I should use to save the checked items or where to store them until the user presses OK/CANCEL buttons. To further define - I know how to retrieve the checked items from the Listview but I am not sure where to store them (i.e. datatable?) until the OK/CANCEl buttons are clicked.
Thank you,
Digicd
-Everyday is a new opportunity
|
|
|
|
|
you done necessarily need to store these values anywhere - they are "stored" by virtue of the fact they are on-screen.
When the user clicks "OK" just get all the currently selected items and save it in whatever way you want.
|
|
|
|
|
Apparently my post was not completely clear . . .
When the user clicks on a folder - a list of companies is retrieved from the database to a dataset, therfore the listview values dynamically change each time the user clicks on a new folder. If the user checked 2 companies on the "A" folder - then clicked on the "B" folder - and went back to the "A" folder the items are no longer checked. Make sense?
Digicd1
-Everyday is a new opportunity
|
|
|
|
|
I am having a problem regarding opening a binary file in VB.net or Vb 6 and then
tramsmit it to a Serial port.
Please give a solution if any?
from Mayur Gondaliya
Mayur
|
|
|
|
|
I am new to VBScripting. have only worked on VC++,C# etc.Kindly help me with this.
I have to develop a module using VBScript. The VbScript should be able to open an existing .htm file(this .htm file has a list of drivers name and file name).
The VBScript has to basically be able to open this .htm file, pick out all drivers name and associated file name and log the driver and file names into a simple text file.
Being new to VBScripting i do not have an idea how to go ahead. Pls suggets me a way to do this - if there is a sample cose existing kindly inform me.
Thanks in advance.
Awaiting a reply soon.
Sincerely
Giftsana
|
|
|
|
|
hi i'm very novice in vb.net.this is my larning stage.
can any body tell me how can i read the field of database to make the login page.
if could then please provide th appropriat code
thanx
Aavesh
|
|
|
|
|
Hi Aavesh ,
This is the code to validate User ID & Password from DataBase.
If u r using SQL
imports System.Data.SqlClient
Dim Command as SqlCommand
dim DR as SqlDataReader
Dim Con as new SqlConnection("Server=server name;DataBase=database name;User Id=login id; Password=password;")
write this code in a Button Click.
Dim strCommand as String ="Select * from Login_Table where UserName_Column= ' " & txtUser.Text & " ' and Password_Column= ' " & txtPassword.Text & " '"
Command = New SqlCommand(strCommand,Con)
Con.Open()
DR = Command.executeNonQuery()
Con.Close()
If DR.HasRows = True then
MsgBox("Welcome")
Else
MsgBox("User Name or Password invalid")
End If
Dr.Close
With Regards,
Chandan Kumar
|
|
|
|
|
Hi there
i want to move to the next tab on click of a button.
Other than the tabstrip button . Please help me to solve this.
bharath.s
|
|
|
|
|
Try:
Me.tabcontrolname.SelectedTab = nameofthetab
or
Me.tabcontrolname.TabPages(x).Select() where x is the index of the tab you want selected
Dean
|
|
|
|
|
Go into the properties, under behaviors and you will find TabIndex, this gives you the order in which the buttons or anything on the screen that you can inter act with, the order in which the item is given focuse, if you want to move from one imput to the next, hope this helps.
|
|
|
|
|
hi all
good morning,
can any one please tell me how can i drag a textbox from one cell in a tablelayoutpanel and drop it to another cell of the same tablelayoutpanel.
this is very urgent
please see if any help can i get
thanks and regards to all
SP
|
|
|
|