|
Thanks for that Richard, it is VB.NET that I'm using. Interesting behaviour, not what I would have expected, useful to know though! Cheers
Jon
|
|
|
|
|
Hi All,
I have a function which will format the numbers that are returned from a variable. That is, if my Resistance is 0.0189015 then it will return 0.018, and if its 0.000065 it should return 0.00006 instead of a zero.
Here is the function
======================================================================
Private Function FormatResistance(ByVal Resistance As Double) As Double
Dim PositionCount As Int16
Dim ResistanceCheck As String
Dim ResistanceString As String
Dim Resistancelength As Int16
ResistanceString = Resistance
'CStr(Resistance)
Resistancelength = ResistanceString.Length
For PositionCount = 3 To Resistancelength '' not worried if resistance is 0.xx so start in 3rd position and checking till the sixth place
If Mid(Resistance, PositionCount, 1) = 0 Then
ResistanceCheck += Mid(Resistance, PositionCount, 1) ' THis is done becos Materials like BRass has almost 0 resistance and if not formatted
'will not add to the material list because of the Isvalid Function check
End If
Next
If ResistanceCheck = "000" Then
Resistance = Format(Resistance, "0.0000")
Else
Resistance = Format(Resistance, "0.000")
End If
Return Resistance
End Function
The problem is, for the Resistance value 0.0000625 the string converted is 6.25E something.SO it fails. Any better idea to handle this ?
Or is there a simpler way of doing this ? Please help
Thanks
|
|
|
|
|
The simplest way is to just convert the incoming number from a numeric value to a string:
Private Function FormatResistance(ByVal Value As Double) As String
Dim psTemp As String
If Value = 0.0# Then
FormatResistance = "0"
Else
'convert double value to string
psTemp = Format(Value, "#0.000000")
If psTemp.Substring(psTemp.IndexOf(".") + 1, 3) = "000" Then
FormatResistance = psTemp.Substring(0, psTemp.IndexOf(".") + 6)
Else
FormatResistance = psTemp.Substring(0, psTemp.IndexOf(".") + 4)
End If
End If
End Function
Note that this function does not do any rounding to anything, it just truncates the number based on the examples you gave.
-- modified at 12:39 Tuesday 18th October, 2005
|
|
|
|
|
I am trying to make a box so that when a person types in a part number, it will search through my database and bring up a datagid with that part number, and all the other data associated with it. I haven't figured out how to link the text box with the datagrid.
|
|
|
|
|
Hi,friends:
we know that we can write win32 console applications with VC++6.0,then how can we just do the same thing with VB6.0?
ThanX in advance!
|
|
|
|
|
The instructions on how to create a VB6 console app by hand would take a few pages. If you are not using, or have never heard of, vbAdvance, I HIGHLY recommend you check his product out: http://www.vbadvance.com/[^]. I've been using it for a few years and I don't know how I lived without it.
|
|
|
|
|
how to print the run time form without going to microsoft world using printscreen key in vb.net as well as vb
himanshu
|
|
|
|
|
using printdocument if you need some sample code email me !
I am Entry level person
|
|
|
|
|
I am working on a simple text editor in vb .net. My problem is one of preserving the the rtf format in the rich textbox when using the property:
RT.RightToLeft = Windows.Forms.RightToLeft.Yes
or
RT.RightToLeft = Windows.Forms.RightToLeft.No
changing the property in either direction will make text in rich texbox turn to simple text and no formatting.
I can use another hidden rich textbox to copy and paste formatted text but I am looking for a more elegant solution.
I would appreciate any help.
Thanks in advance
baankhi
|
|
|
|
|
i wanna kill. what a stupid work , working with raw data. At the end i learnt, how to print raw data print via LPT1 Port . But when i send data , Printer gives error. I'm sure my printer is connected from LPT1 port.
Could Anyone try this code,
Imports System.IO <br />
Imports System.Runtime.InteropServices <br />
<br />
Public Class Form1 <br />
Inherits System.Windows.Forms.Form <br />
Public Const GENERIC_WRITE = &H40000000 <br />
Public Const OPEN_EXISTING = 3 <br />
Public Const FILE_SHARE_WRITE = &H2 <br />
<br />
Dim LPTPORT As String <br />
Dim hPort As Integer <br />
<br />
Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" ( _ <br />
ByVal lpFileName As String, ByVal dwDesiredAccess As Integer, _ <br />
ByVal dwShareMode As Integer, _ <br />
ByRef lpSecurityAttributes As SECURITY_ATTRIBUTES, _ <br />
ByVal dwCreationDisposition As Integer, ByVal dwFlagsAndAttributes As Integer, _ <br />
ByVal hTemplateFile As Integer) As Integer <br />
<br />
Public Declare Function CloseHandle Lib "kernel32" Alias "CloseHandle" (ByVal hObject As Integer) As Integer <br />
Dim retval As Integer <br />
<br />
Public Structure SECURITY_ATTRIBUTES <br />
Private nLength As Integer <br />
Private lpSecurityDescriptor As Integer <br />
Private bInheritHandle As Integer <br />
End Structure <br />
<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click <br />
Dim Texxxt As String <br />
Dim SA As SECURITY_ATTRIBUTES <br />
Dim outFile As FileStream, hPortP As IntPtr <br />
<br />
LPTPORT = "LPT1" <br />
Texxxt = Me.RichTextBox1.Text <br />
hPort = CreateFile(LPTPORT, GENERIC_WRITE, FILE_SHARE_WRITE, SA, OPEN_EXISTING, 0, 0) <br />
<br />
hPortP = New IntPtr(hPort) 'convert Integer to IntPtr <br />
outFile = New FileStream(hPortP, FileAccess.Write, False) 'Create FileStream using Handle <br />
<br />
Dim fileWriter As New StreamWriter(outFile) <br />
'MessageBox.Show(RichTextBox1.Text ) <br />
' fileWriter.AutoFlush = False <br />
fileWriter.WriteLine(RichTextBox1.Text) <br />
fileWriter.WriteLine("Hello World2") <br />
fileWriter.WriteLine("Hello World1") <br />
fileWriter.WriteLine("Hello World2") <br />
fileWriter.Write(Chr(12)) '12 <br />
fileWriter.Flush() <br />
fileWriter.Close() <br />
outFile.Close() <br />
<br />
retval = CloseHandle(hPort) <br />
End Sub <br />
End Class
|
|
|
|
|
Your printer is probably expecting data in its printer control language (i.e. something like PCL, PostScript etc..) but you are sending it plain text.
'--8<------------------------
Ex Datis:
Duncan Jones
Merrion Computing Ltd
|
|
|
|
|
|
I would use the PrintDocument class and use it. That way the printer driver handles all the conversion to printer control language.
However if you have a good reason to have to write to the printer directly you need to know what language(s) that printer expects - this is information that you would need to look in the printer manufacturer's online support pages for.
'--8<------------------------
Ex Datis:
Duncan Jones
Merrion Computing Ltd
|
|
|
|
|
but i cant use Print Document object with dot matrix printers . am i wrong ?
|
|
|
|
|
What ever gave you that idea? Of course you can.
It's not the type of printer that dictates how your going to do this, but rather what you want to print. If you want total control over the printer, then you'll have to use this RAW method. Anything else, and you can use the PrintDocument class.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I tried but whenever i send document to print ; i got error, then i wrote this state to forum , you (Dave) said to me USE RAW PRINT.
I will re-EXPLAIN my problem.
I m working on Accountancy project. We use printers like (OKI-MICROLINE 320,500,321 etc using SLIDING PAPERS) The Reports can be printable from these printers.
1. Could i do this with printdocument object and printpage event?
2. What do i have to do as additional work for SlidingPapers.?
(For example must i use Courier New Font, what will do if i use Arial and Arial Narrow?)
|
|
|
|
|
hey all,
i have a dataset with three related tables in it. Table_1 -> 1-n Table_2 -> 1-n -> Table_3
I build a treeview with Table_1 and show the related rows of Table_2 in a Datagrid (grid_1). By selecting a row in the grid i show the details of that row and all related rows of Table_3 in another grid (grid_2). If i use perfmon to watch all exceptions of my application i get 5 Exceptions each time i select another node in the treeview (each node represents a datarow of Table_1). If I don't assign the second grid with a datasource (in my case a dataview of Table_1) i get no exceptions.
The difference between grid_1 and grid_2 is the assignment of the datasource. The datasource of grid_1 will be assigned in the AfterNodeSelected event of the treeview after positioning the currencymanager tho the right position. the datasource of grid_2 will be assigned at initialization time.
Private Sub trvProducts_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles trvProducts.AfterSelect<br />
If Not Me.trvProducts.SelectedNode Is Nothing Then<br />
<br />
Dim i As Integer = Me.NavigationView.Find(CType(Me.trvProducts.SelectedNode.Tag, Product.Model.dsProduct.tblProductGroupRow).ID)<br />
<br />
Me.Grid_1.SuspendLayout()<br />
Me.Grid_1.DataMember = ""<br />
Me.Grid_1.DataSource = Nothing<br />
<br />
cmGroup.Position = i<br />
<br />
Me.Grid_1.DataMember = "tblProductGrouptblProduct"<br />
Me.Grid_1.DataSource = NavigationView<br />
Me.Grid_1.Refresh()<br />
Me.Grid_1.ResumeLayout(True)<br />
<br />
End If<br />
End Sub<br />
<br />
public Sub New()<br />
<br />
[...]<br />
<br />
NavigationView.Table = Me.Dataset.Table_1<br />
<br />
Me.Grid_2.DataMember = "tblProductGrouptblProduct.tblProducttblProductPrice"<br />
Me.Grid_2.DataSource = NavigationView<br />
<br />
End Sub
Please Help !!
cheers, Bernd
|
|
|
|
|
I've never had this problem before on any other computer or on my previous installation of VS.Net. (I have VS.Net 2003 Pro) What I think is referred to as intellisense (the little context-sensitive drop down box that offers an alphabetical list of suggestions when you're typing code) seems to always be defaulting to something in the "t" range as follows:
When I type txtSomething (a textbox on my form) and then . the box comes up with textlength highlighted as the suggestion.
This happens when I refer to any object (combo box/label/the form itself) in code and want to change a property of that object. It's not really a problem in most cases, but when I want to change or get the text in a text box (like in the example above), I can't simply type txtSomething.text = ... or else the intellisense thinks I want to select .textlength and kindly inserts it for me when I press the space bar after typing text which then produces txtSomething.textlength = ... . the only two ways I can stop it from doing this are by pressing the up arrow key twice after typing text but before pressing the space bar(so as to select text instead of textlength , or just going back to correct it each time.
Generally, I like this feature of VB/VS.net, but it's not working the way I think it's supposed to. Anyone know what's happening? how to shut it off? reset something? thanks in advance
sincerely, Brett Peirce - PolerBear
To err is human; To forgive: divine.
-- modified at 1:58 Tuesday 18th October, 2005
|
|
|
|
|
hey
i have had this problem alot, too, but it was with daSomething.Fill and it kept selecting FillSchema. the best solution i found was to type the same commands over and over, but using something completely different. once it starts selecting the new command for you, then it should be fixed for the other one.
another problem is, (though it not be relavent in this case) is if the desired word comes after the selected word, you will have to type out almost the entire word to get intellisense to select it.
your best bet is to type the "t", scroll to your selection and hit ctrl+space. i'm not sure of any way to "reset" intellisense, though i think there should be.
hope this helps,
stephen
|
|
|
|
|
Thank you greatly. I did happen to notice it suggesting other things for other objects since that post and managed to follow your advice before reading it. Thank you nonetheless for your answer.
sincerely, Brett Peirce - PolerBear
To err is human; To forgive: divine.
|
|
|
|
|
hi all,
iam new to vbscript...
i created one application in VC++.
i would like to give brief explanation abt that...
my application is abt recording process...
when u enter any URL , it opens that url...like yahoo or google..whatever we wish...then ,if we press record button...it starts recording.
onwards what u have done(click,mousemovement,and etc) in that site , it records everything...after that we can save that in one file...
again if we want to playback that,we should open that save file...and we can play it...
For this process i want to write vbscript in a log file with using microsoft script control...how can I? can you please guide me..
iam greatful to u...
|
|
|
|
|
how to search and replace text in a rich text box ???
I am Entry level person
|
|
|
|
|
If you mean doing it through code then one way is:
Dim textToSearch as string = "was"
Dim textToReplace as string = "gonnabe"
Dim textToSearchIn as string = yourRichTextBox.Text
Dim position as integer
position = textToSearchIn.IndexOf(textToSearch)
while position<>-1 ' If found
textToSearchIn = string.concat (textToSearchIn.Substring(0,position)), _
textToReplace, textToSearchIn.substring(position+textToSearch.length-1))
position = textToSearchIn.IndexOf(textToSearch)
end while
yourRichTextBox.Text = textToSearchIn
There may be other, and better, ways of accomplishing it but this should be also easy to understand the approach.
|
|
|
|
|
I did a query in Access and used that table as the datasource. Is there a way to do a SQL statement with multiple joins to an Access table in .Net? It always chokes when I try to include multiple tables. Thanks
Jerry
|
|
|
|
|
i donot really understand, coz as i know you can databind to a table in the dataset and you just specify the dataset name and datatable name!
I am Entry level person
|
|
|
|