|
One thing I forgot to tell you is that the numbers that I am trying to format is coming from a file and being output to an sql database. Here is some code for you to look over just to see what is going on. I am trying to create a function and call the function in the If, Then statements.
Format Function:
Public Function FormatPartNumber(ByVal partnumber As String, ByVal formatstyle As String) As String
FormatPartNumber = String.Format(partnumber, formatstyle)
Below is one function to write the file to database and format numbers the only problem that I am having is that the number that I am trying to format will appear as XXXXX-XXX in the database instead of the actual number.
Private Sub ImportKawasakiUtilityGenerator()
Dim dttable As New DataTable
Dim row As DataRow
Dim CheckforProducts As DataTable
Dim FormattedPartnumber As String
Dim FormattedSupercedePartNumber As String
Dim Conn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Data Feeds\Current\Kawasaki\Utility Generator Only;EXtended Properties=""TeXt;HDR=No;FMT=FiXedLength"""
Dim SQLstr As String = "SELECT * FROM IMINF012.dat"
Dim da As New OleDb.OleDbDataAdapter(SQLstr, Conn)
FormattedPartnumber = vbNull
FormattedSupercedePartNumber = vbNull
da.Fill(dttable)
DataGridView1.DataSource = dttable
For Each row In dttable.Rows
CheckforProducts = ProductExist(row("itemnumber").ToString(), "3")
If Trim(row("formatcodeforitemnumber").ToString()) = "0" Or Trim(row("formatcodeforitemnumber").ToString()) = "" Then
FormattedPartnumber = FormatPartNumber(row("itemnumber").ToString(), "XXXXX-XXX")
ElseIf Trim(row("formatcodeforitemnumber").ToString()) = "1" Then
FormattedPartnumber = FormatPartNumber(row("itemnumber").ToString(), "XXXXX-XXX-XX")
ElseIf Trim(row("formatcodeforitemnumber").ToString()) = "2" Then
FormattedPartnumber = FormatPartNumber(row("itemnumber").ToString(), "XXXXXX-XXXX")
ElseIf Trim(row("formatcodeforitemnumber").ToString()) = "3" Then
FormattedPartnumber = FormatPartNumber(row("itemnumber").ToString(), "XXXXXX-XXXX")
ElseIf Trim(row("formatcodeforitemnumber").ToString()) = "4" Then
FormattedPartnumber = FormatPartNumber(row("itemnumber").ToString(), "XXXXX-XXX-X")
ElseIf Trim(row("formatcodeforitemnumber").ToString()) = "5" Then
FormattedPartnumber = FormatPartNumber(row("itemnumber").ToString(), "XXXXX-XXXX")
ElseIf Trim(row("formatcodeforitemnumber").ToString()) = "6" Then
FormattedPartnumber = FormatPartNumber(row("itemnumber").ToString(), "XXXXX-XXXX-XX")
ElseIf Trim(row("formatcodeforitemnumber").ToString()) = "7" Then
FormattedPartnumber = FormatPartNumber(row("itemnumber").ToString(), "XXXXX-X-X")
ElseIf Trim(row("formatcodeforitemnumber").ToString()) = "8" Then
FormattedPartnumber = FormatPartNumber(row("itemnumber").ToString(), "XXXXXX-X-X")
ElseIf Trim(row("formatcodeforitemnumber").ToString()) = "9" Then
FormattedPartnumber = FormatPartNumber(row("itemnumber").ToString(), "XXXXXX-XXXX-XX")
ElseIf Trim(row("formatcodeforitemnumber").ToString()) = "A" Then
FormattedPartnumber = FormatPartNumber(row("itemnumber").ToString(), "XXXXXX-XXXXX")
ElseIf Trim(row("formatcodeforitemnumber").ToString()) = "B" Then
FormattedPartnumber = FormatPartNumber(row("itemnumber").ToString(), "XXXXXX-XXXXX-XX")
ElseIf Trim(row("formatcodeforitemnumber").ToString()) = "C" Then
FormattedPartnumber = FormatPartNumber(row("itemnumber").ToString(), "XX-")
ElseIf Trim(row("formatcodeforitemnumber").ToString()) = "D" Then
FormattedPartnumber = FormatPartNumber(row("itemnumber").ToString(), "XXX-")
End If
Hope this gives you a better idea of what I am trying to do!
jds1207
|
|
|
|
|
Sorry, I didn't mean to copy all of the If statements.
|
|
|
|
|
This looks like it needs to be refactored pretty badly.
Really, what you need to do is change each line to something like
FormattedPartnumber = string.Format("XXXXXX-XXXXX-XX", row("itemnumber").ToString())
where the XXXX-XXXX-XX bit is replaced by a real format string.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
The database is showing the partnumber now but the number is still not formatted. I think it might have something to do with the function below:
Public Function FormatPartNumber(ByVal formatstyle As String, ByVal partnumber As String) As String
FormatPartNumber = String.Format(formatstyle, partnumber)
End Function
Any ideas?
jds1207
|
|
|
|
|
Hello @ll.
Today i tested something out about referencing. A made a blank vb6 .exe project and added some references (.dll's). i compiled the project and opened it with a hex editor and disassembler. but i couldnt find any text about the included references. the only one which is allways there is msvbvm60.dll. nothing more. how did the compiled programm use the references? where are they listed??
any suggestions??
regards,
steve
|
|
|
|
|
did you actually use any of the ones you referenced? If not they may not be included
|
|
|
|
|
Just because you included a reference does not mean that they actually get imported. You have to use something in those references for the functions you used to show up in the Imports table.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi.
I have a question regarding setting printer properties programmatically.
Here's what needs to be done.
I need to set properties of the Ricoh multi-function printer to have default color set to 'black & white' when user logs into the machine (printer is on a network).
The problem I have I don't know if it's possible. If it is, and the program/script can be created I will call it from a batch file, which runs every time user logs in.
Is there anyway I can use VB.NET or any other languages to set Color to 'black & white' by default for that printer. We are trying to eliminate color printing especially when it's not needed.
Thank you in advance.
-- modified at 16:19 Tuesday 31st October, 2006
|
|
|
|
|
I have an application that I am almost ready to package. What are options to protect your code from being copied by others and deployed to others ? Is there a way to keep your code from being copied ?
|
|
|
|
|
If it's VB.NET, there's not much you can do to stop people reading your code. Protecting how your app deploys for those who don't know how to read the code is another matter, lots of options there.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I'm having a strange problem with my forms in vb.net 2005
I created a new project by copying around forms from old projects.
Now, this new project runs OK (using the startup form of course), but it does not show the startup form as part of the project!
I can only seem to find the form by searching for a text string that I know is in it.
The code for the form is then visible, but the DESIGN of the form is not.
How can I open both the code and the corresponding design?
tia
|
|
|
|
|
did you by chance put the form in a namespace? in 2005 when you put a form in a namespace, you need to put it in the code as well as the designer otherwise your form becomes a class only.
|
|
|
|
|
Hi.
I'm not sure exactly what you mean. Do you mean that I need to have this sub in my code?
Private Sub TopForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If so, then do have it.
I think that my form exists (invisibly to me within the project) in the \my project folder. When I choose "save myproject topform.vb" the form is then also saved in the project's root directory. But then if I try to load the form from the root directory, it's as if the form is there twice and I get "duplicate" errors.
I can't seem to make the form that exists in the \my project folder visible to my project!
thanks again!
|
|
|
|
|
I am folder happy within my projects separating code and functionality. So I have a folder called 'forms'. I not only put all my forms in that folder but I also add a namespace to each form so that each form belongs to the namespace 'Forms'. ex: Dim oFrm as new Forms.Form1 In 2005, they separated the designer from the rest of the code with the introduction of "partial class"es. So if you put a form in a namespace you need to put the namespace above the class of your code as well as the partial class for your form so that each piece belongs the 'forms' namespace.
if you weren't using namespaces, then this obviously wasn't your problem. Have you tried to create a new form and copy the code in from the hidden on to see if that "corrects" the problem.
|
|
|
|
|
nlarson11 wrote: I am folder happy within my projects
Same here, much easier to find your way around.
nlarson11 wrote: I also add a namespace to each form so that each form belongs to the namespace 'Forms'.
Interesting concept, not one that's occured to me before. Do you notice any performance benefits? Or is it just "a thing" you do?
I'd be interested in finding out more - would you write an article on the subject?
|
|
|
|
|
Peformance benefits...I would say no. But it's a good way to organize/categorizing every object/functionality within your project.
Article...well not sure. Some of these guys are bruttle of those that write articles. It would need to be well written and I'm not a gifted documenter... I'll consider it.
Nathan
|
|
|
|
|
nlarson11 wrote: Some of these guys are bruttle
Yep, I've seen. Not shaking in my boots just yet tho, I've got two that I'd like to finish off and submit & to hell with them if they're brutal - it'll only teach (force?) me to write better code.
nlarson11 wrote: I'm not a gifted documenter
Can't be worse than some I've read here already. Give it a try, you've got nothing to lose and plenty to gain.
|
|
|
|
|
I'm having a strange problem with my forms in vb.net 2005
I created a new project by copying around forms from old projects.
Now, this new project runs OK (using the startup form of course), but it does not show the startup form as part of the project!
I can only seem to find the form by searching for a text string that I know is in it.
The code for the form is then visible, but the DESIGN of the form is not.
How can I open both the code and the corresponding design?
tia
|
|
|
|
|
i am trying to connect to excel (visual studio 2003 and excel 2002), but everytime i open a new workbook ,i get an error, saying "old version".
does anybody know help?
|
|
|
|
|
High all,
I have a small problem on a inherited combobox (VS 2005).
The code behind is to have the functionality of a "Readonly" box,
basically like the Text Box, and my readonly textboxes all have another
backcolor (out of our corporate identity stuff...). The combo itself works
just as expected, but with one little thing: it has a sort of ugly white
border around the editing area, seems it just colored the background of
that one...
If anybody had the same kind of problem, please let me know
Thanks
vonb
|
|
|
|
|
Hi
I am fiddling with Composite UI Application Block (CAB) from MS. I have created the application as directed, the modules are also loaded, however, I cannot see the user control loaded on my form.
The code in the InitModule does not get executed - why would be that?
Anybody played with this?
Shreekar
http://shreekarishere.blogspot.com
|
|
|
|
|
I have an treeview control with checkboxes to all its parent and child nodes.
Can anyone give me the code to find the treeview nodes text which are all get checked in their checkboxes in an string array after a button is clicked in that form.
plz help me to find out.
rajamarichamy
|
|
|
|
|
If I am not working by using "TreeView1.Nodes(i).ToString" u can find the text which will be in a loop. Try with this
|
|
|
|
|
Hi All,
How can I Change Local Machine IP Address without rebooting the machine using VB.Net.
As I want to shift from one IP address to another IP address with application the effect should take place without rebooting the system.
Thanks in advance.
Raju
|
|
|
|
|
You'll have to use WMI and the Win32_NetworkAdapterConfiguration[^]to change the IP Address. Also, there is no guarantee that you won't have to reboot the machine.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|