|
hello dave
im sorry but the result is still the same
im still getting 12345 instead of 123.45
i double check everything and the value in the notepad is 123.45
i try using label instead of textbox but the same thing is shown
i try changing the value in notepad to 345,232.45 and this error comes out
An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
Additional information: Input string was not in a correct format.
but if i change it to 123.455,67 it just show me 123455,67
is the problem coming from the notepad?
i change most of the coding as you recommended
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim name, display As String
Dim total, amount, charges As Double
Dim num1 As Double
Dim sr As StreamReader = File.OpenText("info.txt")
Do While (sr.Peek <> -1)
num1 = Double.Parse(sr.ReadLine())
Loop
Text1.Text = num1.ToString()
Label2.Text = num1.ToString()
i'm so confuse on this problem cause i try reading book and it say that this two method should provide me with the answer i was looking for but it seem like it is not
please help me
thank you and sorry for the trouble
Gary the amatuer
|
|
|
|
|
This problem has nothing to do with Notepad what-so-ever.
These are the possibilities:
1) This is not the code your running.
2) The code is not opening the file you think it is.
3) The info.txt file has more to it than you're telling me.
When I tested this code, the only thing in my text file was a single line, "123.45", without the quotes. This code is GARANTEED to return the correct results:
Dim num1 As Double
Dim sr As StreamReader = File.OpenText("D:\test.txt")
num1 = Double.Parse(sr.ReadLine())
TextBox1.Text = num1.ToString()
They way your code is setup, your reading the ENTIRE file first, then returning the last value that was read. Your code can only work if the only thing on each line is a single decimal number without any punctuation except for one period.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
thanks dave for your help
i think i know what is causing all this problem that i have been having so far
i took most of my application build on my PC to my friends PC to test and it all work prefectly as i expected.but when i try at my own PC anouynomous error pop out.
i cant even do the coding below while my friends PC can
formatnumber(1234,2)
formatcurrency(1234,0)
i think this happen cause some of the file needed is missing
the solution that you provide me work well in my friends PC after i send my application to him.
the "123.45" value is able to be shown and calculated as i expected
you might think that im pulling your leg but it is really the truth
and im sorry to cause you such trouble
i have to delete my vb.net program and then reinstall it again and this time i hope no problem will occur to my future programs
again thanks for your help
Gary
|
|
|
|
|
GaryKoh wrote:
formatnumber(1234,2)formatcurrency(1234,0)
?????? What's with the comma's in the place where the decimal point is supposed to go? Is this the format of the numbers in the file? If so, the Parse method will not work unless you go into the Regional and Language Settings control panel and change the Country to the one where this data is coming from. For instance, in Germany, the number 1,000,000.00 (US-English) is represented by 1.000.000,00 The decimals and commas are interchanged.
What I'm trying to get at is the Parse method is locale sensitive. It will parse numbers based on the settings found in the Regional and Language Settings control panel.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hahaha
thanks dave
the problem i have is just the Regional and Language Setting in my computer
it is set to my country setting
but now i have set it to US-English everything is working well
and now i understand it perfectly the parse method is always base on each computer regional setting
thanks
you really help me
thank you
Gary
|
|
|
|
|
I'm am working on a database in MS Access 2000. I have imported data from a text file.
Their are now two fields that imported in to a table:
Title and Subtitle
I want to make a macro or query (anything that is automatic) to combine the two values (Title and Subtitle) into one (MyTitle) for all the records (about 2,953). Thank you in advance.
-Peace
|
|
|
|
|
Not sure if this is what you are looking for but.
UPDATE yourtable SET main.combinedfield = [yourtable]![Title] & " " & [YourTable]![SubTitle];
|
|
|
|
|
Where do I put this code? I am trying to get it to update the field (if it needs to be updated) when the form is open. Or if I can make a macro that would do it.
|
|
|
|
|
I am not sure of your situation but I would suggest using the Acces macro builder and use the formrun or similar event to fire the import. The code is all VBA or VBscript so you may even find some code on Google that will do it for you. If you are importing this file every time the app opens you may need to work out a different strategy since this could eventually lead to errors. Good luck and I hope it helps.
|
|
|
|
|
I'm new to windows programming so please don't laugh.
I have a visual basic .NET program that i've created. I can install it on PCs and it runs fine.
I want to be able to put it on a server that is on our local network, and I want users to be able to run the exe from through their network neighborhood (over the network). My most desirable option is that the program need not be installed locally to be able to run from the network. (Of course .NET framework would have to be installed locally)
As it is now, if I copy the exe to some place on the network and try to run it from there I recieve a unhandled exception error right away, even if the user has write permissions to that directory.
Where do I need to go next with this program to be able to do this? Remote Services???
|
|
|
|
|
You should be able to copy the executable to a share and run it with no problems as long as the required runtimes are installed on the local machine.
If you're getting an exception on the server, then your best bet would be to either install a dev environment on the server to allow you to step through the code and found it where it craps out.
Although, I'd recommend (it help find out what's causing it instead of possibly just fixing it) using the process of elimination in your code by commented certain parts until it starts working and take it from there.
Jeremy Falcon
|
|
|
|
|
Running a .NET program from a shared drive is not the same as running it locally, because of code-access security. Local programs are more "trusted" than remote ones, so depending on what your app is trying to do, it may get a permissions exceptions.
Couple different ways to tackle this:
* modify the .NET policies for your particular application, on each PC (by using the control panel .NET wizards)
* change your app to only do things that it is allowed to in that particular environment. For example, if you are saving files to a local drive, maybe try using isolated storage instead.
* run the app locally
my blog
|
|
|
|
|
As you have two different answers, I just thought I'd wade in and add my own opinion. I'd go with Steven Campbell's reply. I'm guessing the exeption you are getting, although you don't say it, is a Security Exception.
.NET code won't run over a network unless you set the policy to trust it. You can either set up each machine to trust .NET code in a specific directory/share on the network, or you can sign all your dot net code and set the security policy to trust code that has a trusted signature.
If you have a lot of .NET code that is going to be places in lots of different places on the network then I suggest that you sign it all as it will be easier administer the security policies for .NET
I hope this helps.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
My Blog
|
|
|
|
|
Thanks for the help.
How do I sign my .NET code?
|
|
|
|
|
|
You should create a key/pair file with the .NET tool sn.exe found somewhere like here ..\msvisualstudio.net\FrameworkSDK\bin\sn.exe. run this from the command line with -? to show usage. I think to create a snk (Strong name key) file you use -k. look it up in help also, type Sn.exe in the index of help.
After you have the SOMEHTING.snk file you need to add it to your project Obj folder(I think) and to the Assembly.info add this line
<Assembly: AssemblyKeyFile("..\SOMEHTING.snk")>
After you have built the exe you can increase the assembly trust on the users computer using the NET Framework 1.1 Configuration tool
Programs>Administrative tools>...
Configure Code Access Security Policy > Increase Assembly Trust
Browse to the Exe on the network. follow the instructions but you will find a radio button that says something like All assemblies with same assembly public key.
selecting this will prevent you from having to do this everytime you create a new app, provided you build each app with the same SOMEHTING.snk file.
you could also do this config stuff in an MSI file but that you would have to figure out cause I do not know it.
Hope that helped
|
|
|
|
|
Hi,
I have the following Keyboard hook module and would like to convert it so that it can hook application File Open call instead. Could someone help me with this.
...........................................
Module TestHook
Public Const WH_KEYBOARD = 2
Public Const VK_SHIFT = &H10
Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Integer, ByVal ncode As Integer, ByVal wParam As Integer, ByVal lParam As KBDLLHOOKSTRUCT) As Integer
Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Integer) As Integer
Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Integer, ByVal lpfn As Integer, ByVal hmod As Integer, ByVal dwThreadId As Integer) As Integer
Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Integer) As Integer
Public hHook As Integer
Public Function KeyboardProc(ByVal idHook As Integer, ByVal wParam As Integer, ByVal lParam As KBDLLHOOKSTRUCT) As Integer
'if idHook is less than zero, no further processing is required
If idHook < 0 Then
'call the next hook
KeyboardProc = CallNextHookEx(hHook, idHook, wParam, lParam)
Else
'check if SHIFT-S is pressed
If (GetKeyState(VK_SHIFT) And &HF0000000) And wParam = Asc("S") Then
'show the result
MsgBox("Shift-S pressed ...")
End If
'call the next hook
KeyboardProc = CallNextHookEx(hHook, idHook, wParam, lParam)
End If
End Function
End Module
Private Sub Form_Load()
hHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyboardProc, App.hInstance, App.ThreadID)
End Sub
Private Sub Form_Unload(Cancel As Integer)
'remove the windows-hook
UnhookWindowsHookEx hHook
End Sub
...........................................
Thanks,
|
|
|
|
|
You can't convert this to catch a File Open. There is no hook for that. What, exactly, do you want to accomplish by hooking the File System?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I would like to intercept open calls by any applications that try to open files with the *.txt, for example. I would like to perform some routine before the application proceeds with the open.
|
|
|
|
|
You would have to write what is essentially a device driver. The driver would attach to the NTFS file system and report back with the details your looking for. You can't do it entirely in VB.NET. The .NET languages, except for C++, are too high-level for work like this. You could write your app that does the actual reporting in VB.NET, but the driver work is best done in C++.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Would you happen to have a sample of this in C++ or a site that I can go to for more info?
|
|
|
|
|
Nope, and I doubt you'll find many samples either. It requires very deep knowledge of the internals of NTFS and Windows to write one. People usually bill you for that kind of knowledge. But...
There is an example of such a technique in the FileMon utility at www.sysinternals.com. There is no source for it, you you'll see the .dll in the package. Under the Source nav menu on the left side of their page, you'll find a utility called FunDelete. There is source code in its .ZIP file that demonstrates some of the techniques you'll need to get one these drivers running.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks. I will have a look.
|
|
|
|
|
Hi.
I’m trying to write and if then statement that checks to see if a string contains a certain value.
Here is how I thought it worked:
If TheString.IndexOfAny(“This Text”) then
I want the statement to return True if the string contains “This Text” anywhere within the string.
Can anybody tell me how this should be written?
Thanks
Brad
|
|
|
|
|
There is a function in Microsoft.VisualBasic called Instr that can, given two strings, give you the number of times that string2 occurs in string1.
Try using this function
<br />
Function ContainsStr(Str1 As String, Str2 as String) As Boolean<br />
Return (Microsoft.VisualBasic.Instr(Str1, Str2) > 0)<br />
End Function <br />
Hope This Helps
|
|
|
|