|
In vb 6.0 with MS Access using adodb.recordset the below sql statement gives error help please
dim sql as string
sql="Select * from table1 Where Replace(Field1,".","")=" & tokenID
set rs=cn.execute(sql)
Error: Unknown function Replace is used
although the above sql statement works fine in MS Access query
|
|
|
|
|
IMO your problem is with the string literals inside the Replace call; try doubling the double quotes in there.
|
|
|
|
|
Hello,
I am working with a dataset and I just realized that there is a few methods in vb.net to add a new row to a dataset.
Can I simply add a row in figure 1 instead of creating an explicit dataset and a data table because in design time I created a dataset already. Why do I have to explicitly create a dataset and a table and then a row if I am able to add
a new row with new values with a single line code?
Thanks.
Figure 1.
BPRO.NameTable.Rows.Add("Jashua", "Carla", "Chris")
THE USUAL WAY WAS
Figure 2.
Dim NewDS As New BPRO
Dim Rt As New BPRO.NameTable
Dim NewRow As DataRow = NewDS.Tables("NameTable").NewRow
NewRow("Names") = Trim(UserName.Text.ToUpper)
NewDS.Tables("NameTable").Rows.Add(NewRow)
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
As far as I know, it should work. I have used ADO in C++.
|
|
|
|
|
I have an object that raises custom events.
I want to put these objects into a List(of MyClass) (not an Array , and not an ArrayList ). I'm trying to do this:
Private Sub AddItem()
Dim WithEvents obj As MyClass
obj = New MyClass()
MyList.Add(obj)
End Sub
The IDE is puking on the WithEvents thing (saying it's not a valid declaration in a local variable. How do I have to do this? (In C#, this isn't an issue.)
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
I suspect the answer is to omit the WithEvent keyword. When you reference an object in the list you can use the AddHandler statement to associate the relevant event(s) with the appropriate event handling routines.
|
|
|
|
|
WithEvents only applies to class or module level declarations. All it is is syntactic sugar for allowing you to use the Handles clause on procedures and have the events wired up for you.
For locally declared instances that exposes events, you just need to wire up the event handlers yourself (and tear them down later) with AddHandler /RemoveHandler .
John Simmons / outlaw programmer wrote: (In C#, this isn't an issue.)
'cause in C#, you're just wiring everything up yourself anyway. It's really no different in VB.NET.
|
|
|
|
|
Hi all.
I want to create a program in which I want to compare hashvalue of an ordinary file and a same ordinary but damaged file so that I could distinct them by using CRC32 algorithm.
If current CRC32 value of a file is not equal to its actual value then it will show a message that file is damaged otherwise file is not damaged.
Suggest me how can I do this (and give me some piece of code to better understand it).
Thanks.
Gagan
Gagan
|
|
|
|
|
|
Thanks for your help but I have still some doubt.
That example only explain that how to compute CRC32 hash value of a file but how can I differtiate two same files, one is in good condition and one is damaged or infected by some virus, by computing CRC32 hash values of both files.
Suggest me how to do this.
Thanks.
Gagan
|
|
|
|
|
Uhhh...compare the two hash values??
|
|
|
|
|
Dave K is right. If the two files are identical, they will give the same hash value. If the hash values are different, the files are different. Simple as that.
|
|
|
|
|
Oopps...sorry for that stupid question, I got the point.
Thanks to all for your help
Gagan
|
|
|
|
|
So...lemme ask you guys this:
I'm trying to automate a [crappy] pivot table [that doesn't belong to me] where the data is time-phased. Meaning, that each week when I get the pivot table, the date range will be different.
So, how would you attack the problem of only viewing the last four weeks of data?
I wrote some simple pivottable code, but need to make it so the dates are non-specific:
Sub DUMMY()
'
' DUMMY Macro
'
'
With ActiveSheet.PivotTables("PivotTable2").PivotFields("Weekend Sunday Date")
.PivotItems("20090802").Visible = False
.PivotItems("20090809").Visible = False
.PivotItems("20090816").Visible = False
.PivotItems("20090823").Visible = False
.PivotItems("20090830").Visible = False
.PivotItems("20090906").Visible = False
.PivotItems("20090913").Visible = False
.PivotItems("20090920").Visible = False
.PivotItems("20090927").Visible = False
.PivotItems("20091004").Visible = False
.PivotItems("20091011").Visible = False
.PivotItems("20091018").Visible = False
.PivotItems("20091025").Visible = False
.PivotItems("20091101").Visible = False
End With
End Sub
How would you identify the range of dates and then pick the last four to be visible?
|
|
|
|
|
hi,
instead of writting the date as "20091101" generate the date.
|
|
|
|
|
Well, that's the value thats in the pivot table and I can't change the source data. Ideas on how to get around that one?
----------------------------------
I'm not a programmer by trade, so please don't beat me unmerciful.
|
|
|
|
|
How/where do you specify the threading model in a VB.Net app? I tried adding a module with a main() sub and adding the attribute there, but the app never hits this sub.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Set the startup object (in project properties) to "Sub Main".
|
|
|
|
|
If it is a form based application, threading model should be STA and you should not change it as it will break lot of things in Windows Forms.
VB.NET does it automatically for you. If you want to modify something else such as startup form you can do it in the project settings.
|
|
|
|
|
Hi All
I've been adding textboxes, numericupandowns, etc. to the dataGridView Column, and everything was working fine. I even successfully added a combobox to the datagridview column.
However, I have hit a brick wall and can't find my way around it.
I am trying to load items into the combobox (based on items from the database), and then add the combobox to the datagridview. Note that each item that is in the datagrid has its own set of items to be added to the combobox, so when I select any item, I want to be able to use the combobox as a drop down list to select from the list of options.
I have implemented the datagridview column for the combobox and named it 'DropDownColumn'.
Also created the cell and editing control named 'DropDownCell' and 'DropDownEditingControl', respectively.
I don't know how to add individual items into each of the comboboxes for the given items.
My code looks like this:
Public Class DropDownColumn
Inherits DataGridViewColumn
Public Event Change(ByVal sender As Object, ByVal e As System.EventArgs)
Public Sub New()
MyBase.New(New DropDownCell())
End Sub
Public Overrides Property CellTemplate() As DataGridViewCell
Get
Return MyBase.CellTemplate
End Get
Set(ByVal value As DataGridViewCell)
If (value IsNot Nothing) AndAlso Not value.GetType().IsAssignableFrom(GetType(DropDownCell)) Then
Throw New InvalidCastException("Must be a DropDownCell")
End If
MyBase.CellTemplate = value
End Set
End Property
End Class
--------------------------------------
Public Class DropDownCell
Inherits DataGridViewTextBoxCell
Public Sub New()
End Sub
Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, ByVal initialFormattedValue As Object, ByVal dataGridViewCellStyle As DataGridViewCellStyle)
MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle)
Dim ctl As DropDownEditingControl = CType(DataGridView.EditingControl, DropDownEditingControl)
End Sub
Public Overrides ReadOnly Property EditType() As Type
Get
Return GetType(DropDownEditingControl)
End Get
End Property
Public Overrides ReadOnly Property ValueType() As Type
Get
Return GetType(String)
End Get
End Property
Public Overrides ReadOnly Property DefaultNewRowValue() As Object
Get
Return 0
End Get
End Property
End Class
--------------------------
Public Class DropDownEditingControl
Inherits ComboBox
Implements IDataGridViewEditingControl
Private dataGridViewControl As DataGridView
Private valueIsChanged As Boolean = False
Private rowIndexNum As Integer
Public Sub New()
End Sub
Public Property EditingControlFormattedValue() As Object Implements IDataGridViewEditingControl.EditingControlFormattedValue
Get
Return Me.Text
End Get
Set(ByVal value As Object)
If TypeOf value Is String Then
Me.Text = CStr(value)
End If
End Set
End Property
Public Function GetEditingControlFormattedValue(ByVal context As DataGridViewDataErrorContexts) As Object Implements IDataGridViewEditingControl.GetEditingControlFormattedValue
Return Me.Text.ToString()
End Function
Public Sub ApplyCellStyleToEditingControl(ByVal dataGridViewCellStyle As DataGridViewCellStyle) Implements IDataGridViewEditingControl.ApplyCellStyleToEditingControl
Me.Font = dataGridViewCellStyle.Font
Me.ForeColor = dataGridViewCellStyle.ForeColor
Me.BackColor = dataGridViewCellStyle.BackColor
End Sub
Public Property EditingControlRowIndex() As Integer Implements IDataGridViewEditingControl.EditingControlRowIndex
Get
Return rowIndexNum
End Get
Set(ByVal value As Integer)
rowIndexNum = value
End Set
End Property
Public Function EditingControlWantsInputKey(ByVal key As Keys, ByVal dataGridViewWantsInputKey As Boolean) As Boolean Implements IDataGridViewEditingControl.EditingControlWantsInputKey
Select Case key And Keys.KeyCode
Case Keys.Left, Keys.Up, Keys.Down, Keys.Right, Keys.Home, Keys.End, Keys.PageDown, Keys.PageUp
Return True
Case Else
Return Not dataGridViewWantsInputKey
End Select
End Function
Public Sub PrepareEditingControlForEdit(ByVal selectAll As Boolean) Implements IDataGridViewEditingControl.PrepareEditingControlForEdit
' No preparation needs to be done.
End Sub
Public ReadOnly Property RepositionEditingControlOnValueChange() As Boolean Implements IDataGridViewEditingControl.RepositionEditingControlOnValueChange
Get
Return False
End Get
End Property
Public Property EditingControlDataGridView() As DataGridView Implements IDataGridViewEditingControl.EditingControlDataGridView
Get
Return dataGridViewControl
End Get
Set(ByVal value As DataGridView)
dataGridViewControl = value
End Set
End Property
Public Property EditingControlValueChanged() As Boolean Implements IDataGridViewEditingControl.EditingControlValueChanged
Get
Return valueIsChanged
End Get
Set(ByVal value As Boolean)
valueIsChanged = value
End Set
End Property
Public ReadOnly Property EditingControlCursor() As Cursor Implements IDataGridViewEditingControl.EditingPanelCursor
Get
Return MyBase.Cursor
End Get
End Property
Protected Overrides Sub OnTextChanged(ByVal eventargs As EventArgs)
valueIsChanged = True
Me.EditingControlDataGridView.NotifyCurrentCellDirty(True)
MyBase.OnTextChanged(eventargs)
End Sub
Protected Overrides Sub OnValidated(ByVal eventargs As EventArgs)
MyBase.Items.Add(MyBase.Text)
MyBase.OnValidated(eventargs)
End Sub
End Class
-----------------------------------------
Thanks to anyone that could assist!
|
|
|
|
|
Hi!
I want to develop a small program that has hyperterminal functionality to communicate remotely with a data logger and download file using dial-up modem. Any suggestions or links!!
Thanks
AJ
|
|
|
|
|
Google for and read up on the SerialPort class.
|
|
|
|
|
I have to write code that bounces a blue ball inside the panel. Draw ball using the fillellipse of the class Graphics. The ball should be created and begin moving in response to a MouseClick.
Imports System.Threading
Public Class BallClass
Private colorValue As Color
Private radiusValue As Single
Private xValue As Single
Private yValue As Single
Private dxValue As Single 'x velocity
Private dyValue As Single 'y velocity
Private panelWidthValue As Integer
Private panelHeightValue As Integer
Public Sub New(ByVal BallColor As Color, ByVal BallRadius As Single, _
ByVal BallXValue As Single, ByVal BallYValue As Single, _
ByVal BalldX As Single, ByVal BalldY As Single, _
ByVal BallPanelWidth As Integer, ByVal BallPanelHeight As Integer)
Colour = BallColor
Radius = BallRadius
xValue = BallXValue
yValue = BallYValue
dX = BalldX
dY = BalldY
PanelWidth = BallPanelWidth
PanelHeight = BallPanelHeight
End Sub
Public Property Colour() As Color
Get
Return colorValue
End Get
Set(ByVal value As Color)
colorValue = value
End Set
End Property
Public Property Radius() As Single
Get
Return radiusValue
End Get
Set(ByVal value As Single)
radiusValue = value
End Set
End Property
Public Property dX() As Single
Get
Return dxValue
End Get
Set(ByVal value As Single)
dxValue = value
End Set
End Property
Public Property dY() As Single
Get
Return dyValue
End Get
Set(ByVal value As Single)
dyValue = value
End Set
End Property
Public ReadOnly Property X() As Single
Get
Return xValue
End Get
End Property
Public ReadOnly Property Y() As Single
Get
Return yValue
End Get
End Property
Public Property PanelWidth() As Integer
Get
Return panelWidthValue
End Get
Set(ByVal value As Integer)
panelWidthValue = value
End Set
End Property
Public Property PanelHeight() As Integer
Get
Return panelHeightValue
End Get
Set(ByVal value As Integer)
panelHeightValue = value
End Set
End Property
Public Sub Run() 'makes ball move
While True
Thread.Sleep(10)
If (xValue + Radius >= PanelWidth) Or xValue = 0 Then
dX = -dX
End If
xValue += dX
End While
End Sub
End Class
Imports System.Threading
Public Class ballForm
Private ball As BallClass
Delegate Sub ReDelegate()
Private Sub FrmBallTest_MouseClick(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles BallPanel.MouseClick
'colour, radius, x, y, x-velociy, y-velocity, panel width, panel height
ball = New BallClass(Color.Blue, 15, e.X, e.Y, 1, 1, BallPanel.Width, BallPanel.Height)
Dim drawThread As New Thread(New ThreadStart(AddressOf Me.Draw))
drawThread.Start()
Dim runThread As New Thread(New ThreadStart(AddressOf ball.Run))
runThread.Start()
End Sub
Private Sub FrmBallTest_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
BallPanel.Width = 200
BallPanel.Height = 200
End Sub
Private Sub FrmGUIThreads_FormClosing(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.FormClosingEventArgs) _
Handles MyBase.FormClosing
System.Environment.Exit(System.Environment.ExitCode)
End Sub
Private Sub Draw() 'draws ball every 20 ms
While True
Thread.Sleep(5)
Dim b As Graphics = BallPanel.CreateGraphics()
b.FillEllipse(New SolidBrush(ball.Colour), ball.X, ball.Y, _
ball.Radius, ball.Radius)
b.Dispose()
BallPanel.Invoke(New ReDelegate(AddressOf BallPanel.Refresh))
End While
End Sub
End Class
My problem is the ball is moving vertically Its not moving up and down
Thanks
|
|
|
|
|
rbjanaki wrote: My problem is the ball is moving vertically Its not moving up and down
Your code has a lot of problems: you should not unnecessarily use CreateGraphics, you should not draw stuff outside the GUI thread, you should not use Thread.Sleep() inside a painting method, and you should use a timer (preferably a System.Windows.Forms.Timer), to name a few.
Here are some articles you should read:
- crossthreads1[^]
- animation1[^]
PS: as your code doesn't change yValue, the ball will never move vertically.
|
|
|
|
|
Hi, I have a question on what the proper way to remove a installed program from a computer is. If i go to the control panel and use the add/remove programs, it will remove the program, however, if i create shortcuts to that program, those remain on the computer. Is there a special uninstall program function that comes with visual studio maybe? or is there a way to remove all files associated with the program? I would like the user to be able to simply push a button and everything that was installed with the program, shortcuts, files. If anyone can help me with this, it would be greatly appreciated.
Thanks,
|
|
|
|
|