Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Why Won't Changing The Refresh Rate Of Monitor Work In Code.


I found code to change the screen resolution and bit depth in code using the ChangeDisplaySettings() and it works fine. But when I add a refresh rate to the dmDisplayFrequency property it doesn't actually change it. I do the CDS_TEST and it goes through successfully, but the refresh rate just goes to the minium 60 Hz. Other people have had this problem but no one seems to have come up with why it does not work.

Thanks




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Some Help About The Refresh Rate Of The Monitor
I need to find a way to know the refresh rate of the monitor (hertz) at a moment when my app runs how do i find it? I think i have to use the enumdisplaysettings API but how...


Code:
Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" _
(ByVal lpszDeviceName As Long, _
ByVal iModeNum As Long, _
lptypDevMode As Any) As Boolean

Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" _
(lptypDevMode As Any, _
ByVal dwFlags As Long) As Long

Public Const EWX_LOGOFF = 0
Public Const EWX_SHUTDOWN = 1
Public Const EWX_REBOOT = 2
Public Const EWX_FORCE = 4
Public Const CCDEVICENAME = 32
Public Const CCFORMNAME = 32
Public Const DM_BITSPERPEL = &H40000
Public Const DM_PELSWIDTH = &H80000
Public Const DM_PELSHEIGHT = &H100000
Public Const CDS_UPDATEREGISTRY = &H1
Public Const CDS_TEST = &H4
Public Const DISP_CHANGE_SUCCESSFUL = 0
Public Const DISP_CHANGE_RESTART = 1

Type typDevMODE
dmDeviceName As String * CCDEVICENAME
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * CCFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type
thats the thing i have right now...

Set Monitor Refresh Rate..
I have code to switch the resolution
works fine..

problem is that resets the refresh rate to 60hz
No good!
I want to make it 85hz

Any one have any idea?

Thanks

Time-based Physics: How Do I Unlock The Game Loop From The Monitor's Refresh Rate?
Hi everyone,

I am currently trying to add time-based movement and animation into my Direct Draw 7 project. I have noticed a few problems with the code. I am using QueryPerformanceCounter.

It's quite a simple problem really, but I am not sure how to solve it; I have a sub in the main loop called MainTimer that calculates the time elapsed between each time it runs. It puts the time elapsed into a variable called Elapsed, and I am ready to start using it. However...

The game is currently locked at 75 fps (the monitor refresh rate). Now, before I bombard you all with lots more questions regarding time-based physics, I was wondering, how do I make the program so that the main loop runs independently of the monitor's refresh rate?

Secondly, once I have done this, I would obviously need to know when it's time to refresh the image that we see on-screen - how on Earth do I calculate this, considering everyone will have different monitor refresh rates?

Changing Resolution: Refresh Rate Problems
A friend is having a problem with the refresh rate, and I knew the people here are clever, so I hoped you would be able to help:


Quote:




There is a known bug that I am still unable to solve. It consists in the display refresh rate being (re)set too low when changing the display resolution under Windows NT or XP. In other words, everything works fine when the game starts and the resolution is initially changed, but when the game closes and the display resolution is reset to the ORIGINAL resolution, the original refresh rate is NOT properly restored under Windows NT and XP (it is usually reset to only 60Hz). The problem does not seem to occur under Windows9x.

The display resolution is changed (from Visual Basic 6) by using the "ChangeDisplaySettings" API function from the file user32.dll.

Here are the declarations:

Code:
Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (ByVal lpszDeviceName As Long, ByVal iModeNum As Long, lptypDevMode As Any) As Boolean

Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (lptypDevMode As Any, ByVal dwFlags As Long) As Long

Public Const EWX_LOGOFF = 0
Public Const EWX_SHUTDOWN = 1
Public Const EWX_REBOOT = 2
Public Const EWX_FORCE = 4
Public Const CCDEVICENAME = 32
Public Const CCFORMNAME = 32
Public Const DM_BITSPERPEL = &H40000
Public Const DM_PELSWIDTH = &H80000
Public Const DM_PELSHEIGHT = &H100000
Public Const CDS_UPDATEREGISTRY = &H1
Public Const CDS_TEST = &H4
Public Const DISP_CHANGE_SUCCESSFUL = 0
Public Const DISP_CHANGE_RESTART = 1

Type typDevMODE
dmDeviceName As String * CCDEVICENAME
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * CCFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type
Here is the code that does the change:

Code:
Sub SetResolution(ByVal w, ByVal h)
On Error Resume Next
Dim typDevM As typDevMODE
Dim lngResult As Long
Dim intAns As Integer
lngResult = EnumDisplaySettings(0, 0, typDevM)
With typDevM
.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
.dmPelsWidth = w
.dmPelsHeight = h
End With
DoEvents
lngResult = ChangeDisplaySettings(typDevM, 0)
DoEvents
End sub
To call the function, just type:

Code:
setresolution 640, 480

Monitor Rate, Screen Resolution. (???)
I try to change screen resolution whit this code, everything is fine, but, can you tell me, how to change monitor rate? Everytime program changes resolution, the monitor frequency changes to 60 Hz, and everything is blinking like I was in 90's again.... How to change this value? For example to 85Hz with resolution 1024x768 ???


Code:
Option Explicit

Private Const EWX_REBOOT = 2
Private Const CCDEVICENAME = 32
Private Const CCFORMNAME = 32
Private Const DM_BITSPERPEL = &H40000
Private Const DM_PELSWIDTH = &H80000
Private Const DM_PELSHEIGHT = &H100000
Private Const CDS_UPDATEREGISTRY = &H1
Private Const CDS_TEST = &H4
Private Const DISP_CHANGE_SUCCESSFUL = 0
Private Const DISP_CHANGE_RESTART = 1


Private Type typDevMODE
dmDeviceName As String * CCDEVICENAME
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * CCFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type

Private Declare Function EnumDisplaySettings Lib _
"user32" Alias "EnumDisplaySettingsA" _
(ByVal lpszDeviceName As Long, ByVal iModeNum As Long, _
lptypDevMode As Any) As Boolean

Private Declare Function ChangeDisplaySettings Lib _
"user32" Alias "ChangeDisplaySettingsA" (lptypDevMode As Any, _
ByVal dwFlags As Long) As Long

Private Declare Function ExitWindowsEx Lib _
"user32" (ByVal uFlags As Long, _
ByVal dwReserved As Long) As Long

Public Function ChangeDisplayResolution(NewWidth As Long, _
NewHeight As Long) As Boolean

'Usage: ChangeDisplayResolution 800, 600

'Returns: True if succesful, false otherwise

'Comments: Problems have been reported using this code for
'resolutions higher than 1024 X 768. We recommend not using this
'snippet to go above this limit.


Dim typDM As typDevMODE
Dim lRet As Long
Dim iResp As Integer

'typDM = pointer to info about current
'display settings

lRet = EnumDisplaySettings(0, 0, typDM)
If lRet = 0 Then Exit Function

' Set the new resolution.
With typDM
.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
.dmPelsWidth = NewWidth
.dmPelsHeight = NewHeight
End With

'Do the update -- Pass update structure to
'ChangeDisplaySettings API function
lRet = ChangeDisplaySettings(typDM, CDS_UPDATEREGISTRY)
Select Case lRet
Case DISP_CHANGE_RESTART

iResp = MsgBox _
("You must restart your computer to apply these changes." & _
vbCrLf & vbCrLf & "Restart now?", _
vbYesNo + vbInformation, "Screen Resolution Changed")
If iResp = vbYes Then
ChangeDisplayResolution = True
Reboot
End If

Case DISP_CHANGE_SUCCESSFUL
ChangeDisplayResolution = True
Case Else
ChangeDisplayResolution = False
End Select

End Function

Private Sub Reboot()
Dim lRet As Long
lRet = ExitWindowsEx(EWX_REBOOT, 0)
End Sub
i was trying to add one more line in the code :


Code:
With typDM
.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
.dmPelsWidth = NewWidth
.dmPelsHeight = NewHeight
.dmdmDisplayFrequency = 85 '<this one
End With
but it's still 60 Hz after everything is done.
i don't understand, is this variable what i need?

Refresh Rate
hi
i am building a program
it has wight and yellow lins droping from the top of my form
it looks realy dumb becouse it blinks two much how can i stop this
please help
thanx

Refresh Rate
how can, when i change the resolution of the screen, keep the refresh rate of the monitor at its current value. i've noticed that when i turn the resolution down, the refresh gets knocked down as well. for a program i am making, i need this to stay the same. i've seen code for changing resolution, but nothing for keeping the refresh frequency the same.
thanks, wehttam13

Set Refresh Rate
me is a bit noob and i can set refresh rate for my prog
e.g. me running 1024x768 100 hz
when i start my prog with change of res at start to 800x600 it
automaticly set 60 hz
how to change it to the best refresh rate or at least manualy set in code
plz help

Refresh Rate
Hello everybody! This is my first post, hope the question is not too stupid and you can help me. I started DirectX-Programming in VB a few weeks ago, my first try was to create a flicker-free 2D animation. I did this using the DDBLT_WAIT flag with the blt-routines, but then I noticed that different pc's with different graphic-cards have different refresh-rates (I really felt stupid when I recognized this. I programmed something like this with my amiga when I was younger, of course there was no problem, one monitor-frequency, no problem...)

The result is that my animation is running with different speed on different pc's. Then I tried to get the monitor frequency with the help of the function DirectDraw7.GetMonitorFrequency(), this didn't work, I got an error. I have really no idea why. My next try was to get it using the Surface Description (setting the DDSCAPS_REFRESHRATE-flag, using DD.GetDisplayMode, then DDSURFACEDESC2.lRefreshRate) but the only value I get is 0. I really have no idea what I made wrong, has anybody experience with this topic?
Thanks for your help!

BlueBear

Refresh Rate = FPS?
In my DirectDraw 7 game, the FPS does not go higher than the monitor's refresh rate, is this suppose to happen and is there a way to make the FPS higher? It's no problem on my computer at 85Hertz refresh rate but some older monitors may have much lower refresh rates which would result in low fps.

Something About The Refresh Rate
I found throughout the forum many threads stuff about the resolution changing and all that stuff ( I may sound like a newb but) I ONLY WANT a code for the frequency changing to help me understand better, so could someone give to me a version for frequency changing only plz?

Thank you for your collaboration. ( )

Refresh Rate
Can anyone suggest how can i make *.Refresh faster?

I'm using an AS400 system and connect through ADO.

Anyone?

Thanks!!!

Cannot Get Refresh Rate!!
Hi I am wondering if anyone can help me..
I have been trying to determine the refresh rate (in Hz) of the current display mode in VB6. The closest I can get is trying to use the EnumDisplaySettings API call, but in every case the value of .dmDisplayFrequency returns 0. This either means it isn't working or 0 actually means 'Default' or 'Optimal', which doesn't really help.
Now I'm pretty sure I can change the refresh rate by setting .dmDisplayFrequency, but I just want to GET the current refresh rate. Is there any way of doing this? BTW, I'm using Win98SE, so I don't think things like GetDeviceCaps (VREFRESH) will work.

I have tried everything I can think of.. I can get screen resolution, bits per pixel, monitor info, everything EXCEPT refresh rate!!
Any help would be greatly appreciated!
Thanks in advance!

Vb6 Screen Refresh Rate
Hi! I have a question about screen refresh rate. The important thing is that my app, designed for 640x480, re-sets not only their original screen resolution, but especially their frequency upon exiting. After much research, I finally got the 640x480 part and back working fine. Refresh rate is still a problem.

As an example, my own screen is set to 75 Hertz. When I run my app it goes into 640x480 as I want. Freq goes to 60, which I think is adapter default. On exit it had been going back to the proper res, but not the orig hertz - still 60. I learned in my searches to use the following:

b= ChangeDisplaySettings (Null, 0)

The b is a Global Long - I THINK its being used here as an object. Not sure why the code doesn't just Call ChangeDisplay, etc.
Anyway, it is said to be a quick way to restore the whole original screen settings, using that Null, 0 argument. It worked! Got back to 75 or where ever it was origianlly set. And then...compile time, no problem. Then I run the compiled program, it goes to 640x480 fine, hit exit and:

error '91'
Object variable or With block variable not set???

The actual sub code is thus:

i = 0
Do
a = EnumDisplaySettings(0&, i, DevM)
i = i + 1
Loop Until (a = False)

DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT

DevM.dmPelsWidth = HResOrig
DevM.dmPelsHeight = VResOrig

'b = ChangeDisplaySettings(DevM, 0)
b = ChangeDisplaySettings(Null, 0)

Note the remark. The original code had the (DevM, 0) which worked - even compiled - but did not reset the frequency. I replaced with (Null, 0) and its fine in the IDE, but not as compiled exe!

I found on the web that this problem is usually associated with references objects, etc., within other apps, which I don't think I'm doing. I'm using Windows XP Professional Version 5.1.2600 SP2 Build 2600. Tried Set, re-dimming b, etc., no go. What am I missing?

Not sure if there's something in XP the program is not seeing? Why the error only when compiled? Any advice is indeed appreciated!

Help With Screen Refresh Rate
Hi All

I have an app which changes the resolution of a monitor upon start-up. This works very well. I have a problem where the refresh rate is causing a few problems. Users are complaining.

Does anyone know how to change the refresh rate with Visual Basic 6?

Many Thanks

BB

Message At The Refresh Rate.
hi, my friend asked me if i could make a program for him that will blink a message at the refresh rate of the computer, I.E. imperseptabel, he is wondering if he could tech himself vocabulary words with it.

all i want is to display text, nothing fancy like shapes or pictures, but it can't have any flicker (that would be incredibly anoying) any help of with this would be greatly apprecieated, thanks

Text Box Refresh Rate
Hello everyone i need some help
i have a app. that is supossed to show the recieved bytes value(Winsock2.BytesReceived) in a text box,but i cant get it to work properly maybe because it doesnt refresh enough or something

anyone have a clue to help me ? maybe trougha timer or something ?

hope you can help

Recordset Refresh Rate
Hi,

I'm using a frmMain for opening several recordsets and displaying their data in two datagrids and some textboxes, which are grouped by a frame-array (I'm using tabstrip).

I use a modal form (dialog) for adding / changing the data. The problem is that when I close the dialog, the data on the main form isn't refreshed. Not even after closing the recordsets and re-opening them. I have to click the tab-strips(switch) several times, before the data actually refreshes.

This is how I tried handling thins:
When opening the dialog form, all recordsets are closed. New recordsets are opened and data is added/changed. When closing the dialog, the recordsets are closed again and the main-form opens the recordsets and fills the textboxes (and other controls) with the data.
When clicking another tab, again all recordsets will be closed and re-opened.
Somehow just opening, closing and re-opening the recordsets just doesn't work for me.

Please help me.

Cheers,
Patrick.

Graphics Adapter Refresh Rate
Does anyone know of a way of changing the refresh rate of the graphics adapter through code? Whenever my PC boots up, it defaults to 'Optimal', but this flickers quite badly. The adapter seems to lose this setting when the PC is shut down.

I was wondering if there is any way of changing this to 'Adapter Default' though a program which I can put in my startup folder.

Any help would be appreciated. I don't want code, just a few ideas if possible.

Matt

Refresh-rate Control In Directx
Does anyone know how I might give a directx app the ability to change the screen-refresh rate?

Forcing 60hz Refresh Rate (DirectX 7)
My goal is to code some arcade games that run very smoothly and are tied to the vertical blank of each frame so the animation appears to the naked eye silky smooth!

To do this you really need to key your game to the vertical blank. The problem is, computer monitor default refresh rates can be a wide variety of rates. Running a game at 60 frames per second compared to 75 frames per second is a huge difference.

refreshrate=60
Call dd.SetDisplayMode(640, 480, 16, refreshrate, DDSDM_DEFAULT)

I'd like to force the game at 60 hz, is this a reliable way of doing this? Does anyone know of any drawbacks to doing this? Thanks.

Kinda Noobish Question But.. How Do I Stick Fps To The Screen Refresh Rate?
umm when i worked in full screen with DirectX 8 (2D graphics) it waited for the screen to end its refresh before presenting on the screen. but now im working in windowed mode and it doesnt wait, and i fear it can make it flicker.

so how do i force it to wait?
(added my init sub if it needed)

thanks

Refresh Monitor Using Vb
Hi all
I am having a program (VB 6.0) that changes some desktop properties using
certain API.
though the properties are getting changed it gets applied only when i
manually do
refresh (press F5 or through right click ) on desktop
Is there a way i can program the refresh of desktop.
or Like to know if there is some API for system refresh

thanks
vipin

Changing Baud Rate To Less Than 110 In VB
Is it possible to programatically change the Baud rate of the serial port to less than 110, which is the lowest possible setting offered by windows ?

Problems With Changing Playback Rate
Hello,

I'm trying to write an application that will play MPEG or AVI files at different rates. The rate must change during the playback according to an external input. I tried the IMediaSeeking->SetRate( ) method of DirectX but it results in fitful playback that stops for a while every time this method is called. Is there any way to change playback continually without small pauses? The playback window was created with IGraphBuilder->RenderFile and. Any ideas to solve this problem? It does not have to use DirectX, it can use any other API but the playback rate must change without problems. Thanks.

Getting A Clipboard Monitor To Work!!!
Ok I'm having real problems here and I've searched but can't find a good solution.

I want my program to be able to monitor the clipboard for new items, whether it be text or pictures or files (anything that comes through the clipboard), When something changes I want it to display the format and information in 2 listboxes. I don't want to use a timer as a monitor.

I think this is possible through the Win32 API because I've seen similar programs code but it is too complicated to understand.

Any help would be appreciated, I dont mind complicated code as long as someone could explain it.

Cheers

Vishal

Getting App To Work With A Vertical Monitor In VB 6.0?
An application I have written requires that the monitor be flipped so that it sits vertically, so that we can utilize the most vertical screen. Most monitors sit horizontally, and I was wondering if there is a way in VB to take into account the monitor orientation. Basically if you have a VB application, take you monitor and flip it 90 degrees left and sit it upright. Now try to get you application to appear correctly.

Any help is appreciated.



 

Changing The Resolution Of A Monitor
first however I want to find out the maximum resoultion for the computer

Rate The ACII Secret Code
GO TO THE BOTTOM ONES

Download this and Rate it for me

Specs: Around 40K, very easy. Any smart person can probably hack this, and knows the ASCII code anyway.

Download time: Less then a sec

This can be used for sending e-mails in school (Which I plan on doing) when people will tend to 'review' your e-mails.


Thanks to Nullus for the 'decode' code
And this form for the moral suport everyone knows I need

[PS] If anything is spelled wrong, please blame my grammer/ spelling teachers. Thank you

Data1.Refresh - It Don&#039;t Work
this is the code from my program and i have a problem with it.

Private Sub SearchBand_Click()

Dim bandsql As String
bandsql = "Select * from cd_serial_numbers where band_name = ' " & txtband.Text & " ' "
Let Data1.RecordSource = bandsql

Data1.Refresh

End Sub

After i press the button it fails to refresh the grid. The error message is:
Run Time error '3078'

The Microsoft Jet Database engine cannot find the input table or query "". Make sure it exits and that its name is spelled correctly.

Now it does exist and yes it is spelt correctly so what is the problem?????
__________________

MUHAHAHAHA
__________________

My Mshflexgrid Refresh Does Not Work. Help!!!
My mshflexgrid refresh method doesn’t work well

My application show all customers record from database using a hierarchical mshflexgrid called Grid1. User is allows expanding or collapsing record. For instance, user decided to expand the 1st and 3rd records only. Then, the user wants to change the 3rd customer record by double click on the Grid1 to pop up the editor form. User closed the editor form after modification and the Grid1 got focus again.

At this point, my application should be able to show the updated record with the user setting (expand 1st and 3rd record only on Grid1) remained.

I used the following code:

Private Sub Grid1_GotFocus()
Rs.requery
Grid1.refresh
End Sub

But I the Grid1 failed to show the updated information. So, I changed it to the following code to prove the refresh does not work well.

Private Sub Grid1_GotFocus()
Rs.requery
Grid1.datasource = rs
End Sub

Now, the Grid1 show the updated record but expanded all the records instead of keep the user setting of the Grid1 (i.e: expand only 1st and 3rd record).

Can some one help me to show the updated record on the Grid1 by keeping the user setting?

Pls help and Thanks in advance!

Refresh - Requery Won't Work. Access 2k3
I have a form that displays all records in a table with a list box. I have another form that opens and allows you to enter a new record. I want to refresh the first form when the second form closes. I've tried refresh and requery methods and neither one will work. I've even put a button on the first form so I can force the form to refresh/requery and it still doesn't refresh the form. It just keeps the same records that it had. It only refreshes when I close the form and open it back up.

Why won't the refresh and requery methods work??????

Prevent Refresh Of Form Until Work Is Done
Hello,

I have a small but annoying problem:

I load quite some pictures on my form and that takes a few seconds.
Together with the loading of the pictures, also other controls are updated.
Now this is really awful to look at, during the process, some parts of the form become blank and reappear afterwards.

Can you prevent this from happening? I mean can you 'freeze' the form during the work and refresh it at the end??

Thanks for your help !

Christophe

Weird Problem: F8 Can Let Code Work, Normal Run Wont Work?
I have VBA code for ArcMap, but every time when I run it , error message pops up and then my Arcmap is forced to shut off. Then I set up a check point at the place where error pops up, run it, then click F8, the whole process can be finished, very strange, could any one tell me what is the possible reason and help me to get out of it? thx in advance

Yanli

Update:

I try to add some codes (no special meaning, just to use some time) before the place where error pops up, it seems the whole process can run now, getting more weird to me, help, please!

Weird Problem: F8 Can Let Code Work, Normal Run Wont Work?
I have VBA code for ArcMap, but every time when I run it , error message pops up and then my Arcmap is forced to shut off. Then I set up a check point at the place where error pops up, run it, then click F8, the whole process can be finished, very strange, could any one tell me what is the possible reason and help me to get out of it? thx in advance

Yanli

Update:

I try to add some codes (no special meaning, just to use some time) before the place where error pops up, it seems the whole process can run now, getting more weird to me, help, please!



Edited by - alaazz on 11/2/2005 6:14:01 PM

Code To Turn Monitor Off
is there any way i can turn a monitor off using VB ... i just want to put the command into a button thanks

Refresh BackgroundQuery:=False Works/Doesn't Work On Workstations With Same Software
I just received a new laptop, Compaq nc6220, with XPPro and XPOffice. My old laptop was a Compaq Evo N620c, with XPPro and XPOffice. I have a macro that uses ODBC to extract data from a Unix Database and insert the data points each hour into certain columns in an Excel Worksheet. The macro bombs on the line .Refresh BackgroundQuery:= False on the new laptop and provides the useless error...Runtime Error 1004, General ODBC... I have searched the Web and forums for a solution to what seems to be a routine issue, however, I have not been able to find any solution. The old laptop runs the macro flawlessly. I have tried to duplicate all Excel option settings and machine settings...but I really don't know where to go at this point...Please help! I have pasted the code for the macros and bolded the line where it generates the error...


Code:
Sub GetODBC()

' This is the ODBC query to initiate a query of data by calling the macro SubQueryHSR
'

' Removes the share and sets the workbook for exclusive use.
Application.DisplayAlerts = False

If ActiveWorkbook.MultiUserEditing Then
ActiveWorkbook.ExclusiveAccess
End If

' Unprotects all sheets in the workbook, calls macro "unprotek"
unprotek

If Time >= TimeValue("00:00:00 am") And Time < TimeValue("01:00:00 am") Then QueryHSR "00:00:10", "V3": QueryYesterday "22:57:00", "S3"
If Time >= TimeValue("01:00:00 am") And Time < TimeValue("02:00:00 am") Then QueryHSR "01:00:10", "Y3"
If Time >= TimeValue("02:00:00 am") And Time < TimeValue("03:00:00 am") Then QueryHSR "02:00:10", "AB3"
If Time >= TimeValue("03:00:00 am") And Time < TimeValue("04:00:00 am") Then QueryHSR "03:00:10", "AE3"
If Time >= TimeValue("04:00:00 am") And Time < TimeValue("05:00:00 am") Then QueryHSR "04:00:10", "AH3"
If Time >= TimeValue("05:00:00 am") And Time < TimeValue("06:00:00 am") Then QueryHSR "05:00:10", "AK3"
If Time >= TimeValue("06:00:00 am") And Time < TimeValue("07:00:00 am") Then QueryHSR "06:00:10", "AN3"
If Time >= TimeValue("07:00:00 am") And Time < TimeValue("08:00:00 am") Then QueryHSR "07:00:10", "AQ3"
If Time >= TimeValue("08:00:00 am") And Time < TimeValue("09:00:00 am") Then QueryHSR "08:00:10", "AT3"
If Time >= TimeValue("09:00:00 am") And Time < TimeValue("10:00:00 am") Then QueryHSR "09:00:10", "AW3"
If Time >= TimeValue("10:00:00 am") And Time < TimeValue("11:00:00 am") Then QueryHSR "10:00:10", "AZ3"
If Time >= TimeValue("11:00:00 am") And Time < TimeValue("12:00:00 pm") Then QueryHSR "11:00:10", "BC3"
If Time >= TimeValue("12:00:00 pm") And Time < TimeValue("01:00:00 pm") Then QueryHSR "12:00:10", "BF3"
If Time >= TimeValue("01:00:00 pm") And Time < TimeValue("02:00:00 pm") Then QueryHSR "13:00:10", "BI3"
If Time >= TimeValue("02:00:00 pm") And Time < TimeValue("03:00:00 pm") Then QueryHSR "14:00:10", "BL3"
If Time >= TimeValue("03:00:00 pm") And Time < TimeValue("04:00:00 pm") Then QueryHSR "15:00:10", "BO3"
If Time >= TimeValue("04:00:00 pm") And Time < TimeValue("05:00:00 pm") Then QueryHSR "16:00:10", "BR3"
If Time >= TimeValue("05:00:00 pm") And Time < TimeValue("06:00:00 pm") Then QueryHSR "17:00:10", "BU3"
If Time >= TimeValue("06:00:00 pm") And Time < TimeValue("07:00:00 pm") Then QueryHSR "18:00:10", "BX3"
If Time >= TimeValue("07:00:00 pm") And Time < TimeValue("08:00:00 pm") Then QueryHSR "19:00:10", "CA3"
If Time >= TimeValue("08:00:00 pm") And Time < TimeValue("09:00:00 pm") Then QueryHSR "20:00:10", "CD3"
If Time >= TimeValue("09:00:00 pm") And Time < TimeValue("10:00:00 pm") Then QueryHSR "21:00:10", "CG3"
If Time >= TimeValue("10:00:00 pm") And Time < TimeValue("11:00:00 pm") Then QueryHSR "22:00:10", "CJ3"
If Time >= TimeValue("11:00:00 pm") And Time < TimeValue("11:57:00 pm") Then QueryHSR "22:57:00", "CM3"

Calculate
Application.DisplayAlerts = False
Application.CommandBars("External Data").Visible = False

' Protects all sheets of the workbook, calls macro "protek"
protek

If Not ActiveWorkbook.MultiUserEditing Then
' Sets up the shared workbook for automatically saving every 20 minutes and sets conflict resolution to changes being saved win


ActiveWorkbook.SaveAs FileName:=ActiveWorkbook.FullName, _
accessMode:=xlShared
ActiveWorkbook.KeepChangeHistory = False
ActiveWorkbook.AutoUpdateFrequency = 15
ActiveWorkbook.AutoUpdateSaveChanges = True
ActiveWorkbook.ConflictResolution = xlLocalSessionChanges
Application.ScreenUpdating = False

Application.Goto Reference:=Worksheets("Com_ProbLog").Range("D2")

End If


End Sub


Sub QueryHSR(QueryTime, StartCell)
'
' QueryHSR Macro
' Macro recorded 8/3/00 by Jeff Hoffman
'
' ReportTime = InputBox("Enter the Report date: mm/dd/yy")
' If ReportTime = "" Then ReportTime = Format(Date - 1, "mm/dd/yy")
' ReportTime = "" & "{ts '" & Format(ReportTime, "yyyy-m-d") & " 00:00:00'}" & ""

'
'
ReportTime = Format(Worksheets("Com_ProbLog").Range("B2"), "yyyy-m-d")
ReportTime = "" & "{ts '" & ReportTime & " " & QueryTime & "'}" & ""


ActiveWindow.LargeScroll Down:=0
Worksheets("LIMS_XFR").Activate
Range(StartCell).Select
With ActiveSheet.QueryTables.Add(Connection:="ODBC;DSN=XXXX;UID=XXXX;", _
Destination:=Range(StartCell))
.Sql = Array( _
"SELECT POINT_HISTORY.POINT_NAME, POINT_HISTORY.SAMP_TIME, POINT_HISTORY.VALUE" & Chr(13) & "" & Chr(10) & "FROM OAUSER.POINT_HISTORY POINT_HISTORY" & Chr(13) & "" & Chr(10) & "WHERE (POINT_HISTORY.POINT_NAME In ('FI27711C','FI32420R'," _
, _
"'FI13151Q','FI13131Q','FI16201','FI17413F','FI17414F','FI17415F','FI17416F','FI18401Q','FI19411Q','FI19412Q','FI22121Q','FI22122Q','FI22123Q','FI23124Q','FIT22126','TI26601','A02N002A','TI26602','A02N012A','FI26603Q','FI26601Q','FI26604Q'," _
, _
"'FI26602Q','FI25651Q','FI25653Q','FI25655Q','MI25651N','MI25653N','MI25655N','FQ26609','FQ26608','FQ26610','KQBLR1','KQBLR2','AI30857B','AI30858B','AI30854B','AI30855B','AI30851B','AI30852B','AI30851','AI30852','AI30853','AI30854','AI30855'," _
, _
"'AI30856','AI20101','FI30851Q','FI30854Q','FI30852Q','FI30855Q','FI30853Q','FI30856Q','FI30861Q','FI30862Q','FI30863Q','FI30864Q','FI30865Q','FI30866Q','AI27704','FI28405C','FI28406C','FI28407C','LI50105','FI38501Q','FI38502Q','FI38503Q','FI38500C'," _
, _
"'FI39500C','FI22125F','KQ36415','KQ36416','KQ36417','KQ31225','BLR1OILT','BLR2OILT','BLR1GAST','BLR2GAST')) AND " _
, "(POINT_HISTORY.SAMP_TIME=" & ReportTime & ")")
.FieldNames = False
.RefreshStyle = xlOverwriteCells
.RowNumbers = False
.FillAdjacentFormulas = False
.RefreshOnFileOpen = False
.HasAutoFormat = True
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.RefreshPeriod = 0
.Refresh BackgroundQuery:=False
.SavePassword = True
.SaveData = True
End With


End Sub

Help With VB Code To Monitor A Folder Size
Does anybody know how I can monitor the size of a folder, so that when it reaches a particular memory size, a message can appear to alert the user. I think I need to set-up a variable that can be linked to the size of the folder, then possibly a case statement with various messages.
Any help would be appreciated.

Thanks

VB Code Needed To Monitor Process And Report
i need a VB code to check if a certain process is using cpu time or idle

and could that code be placed as a macro in excel to turn a cell (say A2) red for using CPU time or green if idle?????????

thanks
Mark
mjc2002@yahoo.com

Serial Port Monitor Source Code
I am looking for some code that would give me the ability to monitor data from a serial
port. I have found some programs on the web but no souce code to incorporate into a VB
program. If anybody has any info (ActiveX or DLL) on this it would be much appreciated.

Thanks,

price1

Changing To Fax. Doesn't Work.
I use common dialog to send a form to a certain printer. That works fine.

But when I try to send it to another printer (in this case Winfax)
It opens my printer dialog as expected but it sends the form to my default printer. It doesn't take in consederation my change of printers.
Why?

Why Is My Code Not Working "good Rate For Your Help"
VB Code:
Private Sub Command4_Click()  Dim e As Integere = Text3.TextDim HTML As HTMLDocument    Dim href As HTMLAnchorElement    Set HTML = WebBrowser1.Document    For Each href In HTML.links           If href.innerText = e Then            href.Click                                    Exit For        End If    NextEnd Sub

Changing Wallpaper, Doesnt Really Work?
Hello, i tried to change my wallpaper with visual basic, but it doesnt really work. When i try my code thewn instead that i changes the wallpaper of my choice it changes the background to something blue. Why is that??
this is my code


Code:
Private Declare Function SystemParametersInfo Lib "user32" Alias _
"SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, _
ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long

Const SPI_SETDESKWALLPAPER = 20
Const SPIF_UPDATEINIFILE = &H1

Private Sub Command1_Click()
SystemParametersInfo SPI_SETDESKWALLPAPER, 0, "C:Documents and SettingsAll UsersDocumentenMijn afbeeldingenVoorbeelden van afbeeldingenWinter.jpg", SPIF_UPDATEINIFILE
End Sub

Private Sub Form_Load()
Command1.Caption = "Set Wallpaper"
End Sub

Changing Color && Bold Doesn't Work!
Iam try to alter the color and boldness of cells in Excel using VBA. The code I use is for example:

Worksheets("1").Range("W1").Font.ColorIndex = 1
Worksheets("1").Range("W1").Font.Bold = False

THis work perfectly for most cells although I have a few that won't change. Even if formatted in Excel. The cells aren't locked or protected!

Does anyone have any suggestions?

Thanks

Gwyn

Help With Code!! Whats Wrong With This Code, Command5 Does Not Work.
this command does not work i have no idea could i get some help!!

Code:
Private Sub Command5_Click()
Dim score1 As Integer
Dim score2 As Integer
score1 = Label12.Caption
score2 = Label13.Caption
Dim bet As Integer
Dim money1 As Integer
Dim money2 As Integer
bet = Label14.Caption
money1 = Label10.Caption
money2 = Label11.Caption
If score1 > score2 Then
money2 = money2 - bet
money1 = money1 + bet
End If
If score2 > score1 Then
money1 = money1 - bet
money2 = bet + money2
End If
End Sub
if you need the whole code here it is......

Code:
Private Sub Command1_Click()
Timer1.Enabled = True
Label3.Caption = " "
End Sub

Private Sub Command2_Click()
Dim goodroll2 As Integer
Dim goodroll As Integer
Dim goodrolladd As Integer
goodroll = Label1.Caption
goodroll2 = Label2.Caption
goodrolladd = goodroll + goodroll2
If goodrolladd > 7 Then Label3.Caption = "Good Roll!!!"
Timer1.Enabled = False
If Label1.Caption = 1 And Label2.Caption = 1 Then Label3.Caption = "snake eyes!!"
If Label1.Caption = 1 And Label2.Caption = 1 Then Timer2.Enabled = True
Label12.Caption = goodrolladd
End Sub

Private Sub Command3_Click()
Timer3.Enabled = True
Label3.Caption = " "
End Sub

Private Sub Command4_Click()
Dim goodrolltwo As Integer
Dim goodrolltwox2 As Integer
Dim goodrolladdtwo As Integer
goodrolltwo = Label8.Caption
goodrolltwox2 = Label9.Caption
goodrolladdtwo = goodrolltwo + goodrolltwox2
If goodrolladdtwo > 7 Then Label3.Caption = "Good Roll!!!"
Timer3.Enabled = False
If Label8.Caption = 1 And Label9.Caption = 1 Then Label3.Caption = "snake eyes!!"
If Label8.Caption = 1 And Label9.Caption = 1 Then Timer2.Enabled = True
Label13.Caption = goodrolladdtwo

End Sub

Private Sub Command5_Click()
Dim score1 As Integer
Dim score2 As Integer
score1 = Label12.Caption
score2 = Label13.Caption
Dim bet As Integer
Dim money1 As Integer
Dim money2 As Integer
bet = Label14.Caption
money1 = Label10.Caption
money2 = Label11.Caption
If score1 > score2 Then
money2 = money2 - bet
money1 = money1 + bet
End If
If score2 > score1 Then
money1 = money1 - bet
money2 = bet + money2
End If

End Sub

Private Sub Command6_Click()
Label14.Caption = Text3.Text
Text3.Text = " "
End Sub

Private Sub Form_Load()
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
End Sub




Private Sub Timer1_Timer()
Label1.Caption = Int((0 - 7 + 1) * Rnd + 7)
Label2.Caption = Int((0 - 7 + 1) * Rnd + 7)
End Sub

Private Sub Timer2_Timer()
Label3.ForeColor = Int((&HFFFFFF - &H400040 + 1) * Rnd + &H400040)
End Sub

Private Sub Timer3_Timer()
Label8.Caption = Int((0 - 7 + 1) * Rnd + 7)
Label9.Caption = Int((0 - 7 + 1) * Rnd + 7)
End Sub

Dlls Callback Work In P-Code But Not Native Code
OK I am so confussed I have made some software using some callbacks to a 3rd party Dlls. When I run the software compiled as P Code everytihng works fine. When I compile it as Native code it causes my software to exit. The problem is when I compile it as P code some of my other controls seem to stop working. I was just wondering if any body out there could tell me what is going on or how to fix this.
Thanks...

Code Doesnt Work When Im Adding Some Other Code...[Solved]
Hi...
When im adding some code, all of the other code stops working
Here's the code:
VB Code:
If Left$(strData, 9) = "USERLOGIN" Then        strArray2 = Split(strData, vbCrLf)        If ReadINI(App.Path & "users.ini", Right$(strArray2(1), Len(strArray2(1)) - 13), "Password", vbNullString, 100) = Right$(strArray2(2), Len(strArray2(2)) - 13) Then            '<:-) :WARNING: Empty String assignment updated to use vbNullString            '<:-) :PREVIOUS CODE : If ReadINI(App.Path & "users.ini", Right$(strArray2(1), Len(strArray2(1)) - 13), "Password", "", 100) = Right$(strArray2(2), Len(strArray2(2)) - 13) Then            If ReadINI(App.Path & "users.ini", Right$(strArray2(1), Len(strArray2(1)) - 13), "Banned", vbNullString, 100) = "True" Then                '<:-) :WARNING: Empty String assignment updated to use vbNullString                '<:-) :PREVIOUS CODE : If ReadINI(App.Path & "users.ini", Right$(strArray2(1), Len(strArray2(1)) - 13), "Banned", "", 100) = "True" Then                sckIntro(Index).SendData "BANNED"                Exit Sub            End If            If lstUsers.ListCount < 20 Then              sckIntro(Index).SendData "FULL"              Exit Sub            End If                 [b]     Dim i As Integer            For i = 0 To lstUsers.ListCount - 1            lstUsers.ListIndex = i            If lstUsers.Text = Right$(strArray2(1), Len(strArray2(1)) - 13) Then            sckIntro(Index).SendData "ALREADYLOGGEDIN"            Exit Sub            Next i            End If[/b]                        sckIntro(Index).SendData "GOODLOGIN"            lstActions.AddItem "[" & Format$(Time, "hh:mm:ss") & "] " & Right$(strArray2(1), Len(strArray2(1)) - 13) & " has connected."            AddHScroll lstActions         Else 'NOT READINI(APP.PATH...            sckIntro(Index).SendData "BADLOGIN"            lstActions.AddItem "[" & Format$(Time, "hh:mm:ss") & "] Someone tried to login with a bad username or password!"            AddHScroll lstActions        End If    End If
The code works fine without the bolded part...
When i add it, the code stops working and its giving errors!
What should i do?

Thanks!

Need Help: VB6 API Button Click Code Doesn't Work; VB.NET Code Does?!
I am baffled. My VB.NET code works, but my VB6 code does not. I need to know what is wrong with the VB6 code and why doesn't behave the same as the .NET code?

VB6 Code:
Code:
' in a BAS module
Public Declare Function SendMessage2 Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
    ByVal wParam As Long, lParam As Long) As Long

Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const MK_LBUTTON = &H1

‘in a Class
Public Sub DoWindowAction(ByVal vlngHWND As Long)
    Dim lngReturn As Long
    lngReturn = SendMessage2(vlngHWND, WM_LBUTTONDOWN, MK_LBUTTON, 0)
    lngReturn = SendMessage2(vlngHWND, WM_LBUTTONUP, 0, 0)
    'lngReturn = SendMessage2(vlngHWND, BM_SETSTATE, 1, 0)
End Sub


The commented out line with the BM_SETSTATE gets me a little closer. But even with this in I need to set focus to the application that contains the button I am trying to click with vlngHWND and then move focus to another app. What is going on???

VB.NET code:
Code:

Friend Class API
    <DllImport("user32.dll")> _
    Public Shared Function SendMessage(ByVal hwnd As IntPtr, ByVal wMsg As Integer, _
        ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    End Function

    Public Const WM_LBUTTONDOWN As Integer = &H201
    Public Const WM_LBUTTONUP As Integer = &H202

End Class

'in a form
    Private Sub ClickButton()
            API.SendMessage(lngHWND, API.WM_LBUTTONDOWN, 1, 0)
            API.SendMessage(lngHWND, API.WM_LBUTTONUP, 0, 0)
    End Sub


Thanks,
Eric

Copyright © 2005-08 www.BigResource.com, All rights reserved