|
Hi Luc,
I have also tried this code that I think is what you are talking about. When I try to open the Word doc that is in the temp folder, it tells me that it is corrupt. It does however do a recovery and the document opens fine.
Dim conn = New SqlConnection(My.Settings.Maintenance_ManagementSQLConnectionString)
Dim EQ As String = Me.Monsanto_Equip_NoTextBox.Text.ToString
Dim AreaCMD As New SqlCommand()
Dim wordDoc As Byte()
AreaCMD.Connection = conn
AreaCMD.CommandText = "SELECT LOTO FROM [tower]where [monsanto equip no] = '" & EQ & "'"
conn.Open()
wordDoc = AreaCMD.ExecuteScalar()
File.WriteAllBytes("C:\Temp\WordDoc.docx", wordDoc)
|
|
|
|
|
A simple check: do the input and output file have the same length (when going file1 -> DB -> file2)?
Not sure what is wrong, however you could verify, without using Word, whether your file remains identical when going from file to database and back to file.
And why is it you use an explicit Open() and Read(), you could do a File.ReadAllBytes() exactly the same as in your WriteAllBytes().
|
|
|
|
|
Luc,
I know that this is probably not the proper way to handle this, but it does work. I set the open and repair to true on the open document. Thanks for your help!
Dim conn = New SqlConnection(My.Settings.Maintenance_ManagementSQLConnectionString)
Dim EQ As String = Me.Monsanto_Equip_NoTextBox.Text.ToString
Dim AreaCMD As New SqlCommand()
Dim wordDoc As Byte()
AreaCMD.Connection = conn
AreaCMD.CommandText = "SELECT LOTO FROM [tower]where [monsanto equip no] = '" & EQ & "'"
conn.Open()
wordDoc = AreaCMD.ExecuteScalar()
File.WriteAllBytes("C:\Temp\WordDoc.docx", wordDoc)
Dim appWord As New Word.Application
Dim docWord As New Word.Document
docWord = appWord.Documents.Open("C:\Temp\WordDoc.docx", , True, , , , , , , , , , True, , , )
appWord.Visible = True
|
|
|
|
|
Jason, please make use of the code block pre tag when posting code, it makes it easier to read and formats it also if you set the attribute lang="vb"
see;
Dim conn = New SqlConnection(My.Settings.Maintenance_ManagementSQLConnectionString)
Dim EQ As String = Me.Monsanto_Equip_NoTextBox.Text.ToString
Dim AreaCMD As New SqlCommand()
Dim wordDoc As Byte()
AreaCMD.Connection = conn
AreaCMD.CommandText = "SELECT LOTO FROM [tower]where [monsanto equip no] = '" & EQ & "'"
conn.Open()
wordDoc = AreaCMD.ExecuteScalar()
File.WriteAllBytes("C:\Temp\WordDoc.docx", wordDoc)
Dim appWord As New Word.Application
Dim docWord As New Word.Document
docWord = appWord.Documents.Open("C:\Temp\WordDoc.docx", , True, , , , , , , , , , True, , , )
appWord.Visible = True
|
|
|
|
|
You're welcome.
|
|
|
|
|
I am running up against a wall on this.
I am trying to save modified screen grab image objects as monochrome tiff files. I am isolating a particular color and making the image monochrome.
Dim imgProc As Image
'grabs portion of entire screen
imgProc = CropBitmap(SrcImg, rect)
'sharpens image to simplify isolation
imgProc = SharpenImage(imgProc, dChatSharpSetting)
'isolates particular color to make color monochrome
imgProc = IsolateImageColor(imgProc, ChatAlphaSetting, cChatIsoColor)
No matter what I do after this point, I have yet to figure out how to save the image properly. I come out with 32 bit tiff files (seems to be a default).
I am sure this is gotta be an oversight solution. Any help would be appreciated.
|
|
|
|
|
Hi,
I'm not sure what these methods are. Do they belong to some CodeProject article? if so, you might want to ask your questions there, in the forum underneath the article. Are you using some library? if so, you should tell us, and provide a link to it. Or did you develop them yourself?
A .NET Image is actually a Bitmap (unless it is a vector drawing); Bitmaps use one of several PixelFormats; and Bitmap.Save() knows how to generate different ImageFormat file types, although not all combinations are supported.
If you start from a general-purpose color image and want only a single color component, it makes most sense to switch to a more specific PixelFormat (provided Save is accepting it for the .Tiff format you want).
How is IsolateImageColor() going about? If it is yours, you'll have to provide more information here.
|
|
|
|
|
My apologies. new to posting problems the functions listed were ones I wrote specific to the program I am writing to give a history to the image. Basically through the three calls it cuts out a portion of a bigger image, then minimizes the shading, and then does a monochrome image based on a user-defined color to isolate. This gives me a monochrome image I am wanting to put through Tesseract via a different program. I am running into a problem in that tesseract only supports from 1 bpp (monochrome) to 8 bpp (256 color). My images keep coming out at 32bit when I try to save images as tiff images. I was wondering if there is a way to force the color depth through the Image class, or some other way I havent found?
|
|
|
|
|
There are a couple of Bitmap constructor overloads that take a PixelFormat parameter; you should use one of them when going from color to grayscale. If you simply modify an existing Bitmap, it will retain its original PixelFormat, so even if you were to turn all pixels of a color image to some shade of gray, it would still be a color image technically. I must warn again, first check Bitmap.Save takes the PixelFormat,ImageFormat combination you choose.
|
|
|
|
|
I have thought that I posted this a few days ago but cannot see it.
We are planning our migration from XP VisStudio 2005 (VB.NEt) to either Windows7 2008 or 2010 (probably 2010 if it is workable) but have some startup issues.
It seems that in VS 2005 if you had an execution error during IDE testing it stops and gives you an error msg if no Try/Catch. In 2008 and 2010 it just returns from the method.
e.g.
Sub forms_load ...
Dim i as short = 0
i = 1 / i (Error Divide by zero error - Overflow Exeption)
i = i
end sub
In VS 2005 would stop on the Error. In 2008 and 2010 no message and the form is just displayed.
The i = i is not executed.
This must be some setting or directive that we have overlooked.
When taking that same project from 2005 and opening in 2010 the results where strange. It converted then when tried to run in IDE it terminated. On retry it would not step through and seems all screwed up. I tries the bad instruction and then says not working.
Is 2010 stable and usuable to use?
|
|
|
|
|
|
Hi,
1.
you can reach a list of your latest messages through your profile page; see here[^]. The message you have somehow lost is now the second on that list.
2.
Your question was asked and answered two days ago.
3.
If you were getting strange results, I haven't found a reason yet to blame VS2010.
|
|
|
|
|
It maybe would help if you read the documentation for both Operands, rather than dismiss your previous answers and ask again.
The \ operand will always raise a DivideByZero Exception.
The / operand will raise different exception depending on the type, from the Docs;
If expression2 evaluates to zero, the / operator behaves differently for different operand data types. The following table shows the possible behaviors.
Floating-point ( Single or Double) : Returns infinity ( PositiveInfinity or NegativeInfinity), or NaN (not a number) if expression1 is also zero
Decimal : Throws DivideByZeroException
Integral (signed or unsigned) : Attempted conversion back to integral type throws OverflowException because integral types cannot accept PositiveInfinity, NegativeInfinity, or NaN
|
|
|
|
|
In rewriting a website, I have found it useful to be able to select the first non-empty value from a list, where "empty" is defined as Nothing , DBNull.Value and String.Empty . The code I wrote looks like this:
Public Shared Function Coalesce(ByVal ParamArray Items() As Object) As Object
Dim Result As Object = Nothing
For Each Obj As Object In Items
If Obj IsNot Nothing AndAlso Obj IsNot DBNull.Value Then
If Not String.IsNullOrEmpty(Obj.ToString) Then
Result = Obj
Exit For
End If
End If
Next
Return Result
End Function
This way, I could write something like this:
Response.Write(Toolbox.Coalesce(DR("TerminatedDate"), "%nbsp;").ToString)
(Yeah, the nbsp is wrong; I couldn't get it to show up otherwise.) The inputs might be various types -- database fields, date variables, strings, etc. The output will almost always be converted into a String , but not necessarily.
This looks like it should do what I want, but I'm not fully convinced. Any suggestions on how to improve this?
|
|
|
|
|
I wrote an extension method for this not too long ago.
<System.Runtime.CompilerServices.Extension()> _
Public Function GetColumnAsString(ByVal rdr As System.Data.IDataReader, ByVal columnName As String, Optional ByVal valueIfNull As String = "") As String
Dim obj As Object
If rdr Is Nothing Then
Return valueIfNull
Else
obj = rdr(columnName)
If obj IsNot Nothing AndAlso obj.Equals(DBNull.Value) = False Then
Return obj.ToString()
Else
Return valueIfNull
End If
End If
End Function
Note: it does not check for make sure the column specified exists.
Using your example it would be
Response.Write(DR.GetColumnAsString("TerminatedDate", "%nbsp;"))
You could also embed it for more of a coalesce functionality.
Response.Write(DR.GetColumnAsString("TerminatedDate", DR.GetColumnAsString("SomeOtherDate", "%nbsp;"))
|
|
|
|
|
Does anyone has an idea how to implement single sign on using VB6/ASP?
|
|
|
|
|
Single Sign-on to what? You're going to have to explain what you want to do, beside just using "Single Sign-on".
|
|
|
|
|
I got application in ASP/VB6. I need to connect it to an application called Vebnet.
When a user logins my application he will have a link which will redirect him to Vebnet.
|
|
|
|
|
How is your application going to know what username/password to send to this application? How does this application ask for the credentials?? Do you have to source for this "Vebnet"?
You implement single-sign by writing code in the application that is going to support single sign on, not in some shell application that tries to force another app to accept a login.
|
|
|
|
|
Hi All
How can set visible properties false of PowerPoint? I am useing vb 6.0.
Dim pPT As PowerPoint.Application
Dim pPTopen As PowerPoint.Presentation
Dim PptName As String
PptName = "c:\nice.ppt"
Set pPT = New PowerPoint.Application
pPT.Visible = True
Set pPTopen = pPT.Presentations.Open(PptName)
How can i use pPT.Visible = False
When i use pPT.Visible = False then i got error.Error is here
Run-time error '-2147188160(80048240)'
Application (Unknown mwmber) : Invalied request.Hiding the application window is not allowed.
Thanks in advance
|
|
|
|
|
|
Thanks foe reply
But there is no +ve output.I need visible=False or hide powerpoint application.
There is no any option to hide or flas powerpoint application.
Please he me
|
|
|
|
|
what do you think of this
Const SW_HIDE = 0
Const SW_SHOWNORMAL = 1
Const SW_SHOWMINIMIZED = 2
Const SW_SHOWMAXIMIZED = 3
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Const ERR_NO_WINDOW_HANDLE As Long = 1000
Const ERR_WINDOW_LOCK_FAIL As Long = 1001
Const ERR_VERSION_NOT_SUPPORTED As Long = 1002
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As Long) As Long
Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
Declare Function UpdateWindow Lib "user32" (ByVal hwnd As Long) As Long
Sub sOpenPowerpoint()
Dim pPT As PowerPoint.Application
Dim pPTopen As PowerPoint.Presentation
Dim PptName As String
PptName = "C:\A\Nice.pptx"
Set pPT = CreateObject("PowerPoint.Application")
pPT.Visible = True
Set pPTopen = pPT.Presentations.Open(PptName)
nHandle = fHandle
ShowWindow nHandle, SW_HIDE
End Sub
Function fHandle() As Long
Static hwnd As Long
Dim VersionNo As String
' Get Version Number
VersionNo = Left(Application.Version, InStr(1, Application.Version, ".") - 1)
' Get handle to the main application window using ClassName
Select Case VersionNo
Case "8" ' For PPT97:
hwnd = FindWindow("PP97FrameClass", 0&)
Case "9" ' For PPT2K:
hwnd = FindWindow("PP9FrameClass", 0&)
Case "10" ' For XP:
hwnd = FindWindow("PP10FrameClass", 0&)
Case "11" ' For 2003:
hwnd = FindWindow("PP11FrameClass", 0&)
Case "12" ' For 2007:
hwnd = FindWindow("PP12FrameClass", 0&)
Case Else
Err.Raise Number:=vbObjectError + ERR_VERSION_NOT_SUPPORTED, _
Description:="Supported for PowerPoint 97/2000/2002/2003 only."
Exit Function
End Select
If hwnd = 0 Then
Err.Raise Number:=vbObjectError + ERR_NO_WINDOW_HANDLE, _
Description:="Unable to get the PowerPoint Window handle"
Exit Function
End If
If LockWindowUpdate(hwnd) = 0 Then
Err.Raise Number:=vbObjectError + ERR_WINDOW_LOCK_FAIL, _
Description:="Unable to set a PowerPoint window lock"
Exit Function
End If
fHandle = hwnd
End Function
|
|
|
|
|
I guess you missed the copyright on that code snippet...
' --------------------------------------------------------------------------------
' Copyright ©1999-2009, Shyam Pillai, All Rights Reserved.
' --------------------------------------------------------------------------------
' You are free to use this code within your own applications, add-ins,
' documents etc but you are expressly forbidden from selling or
' otherwise distributing this source code without prior consent.
' This includes both posting free demo projects made from this
' code as well as reproducing the code in text or html format.
' --------------------------------------------------------------------------------
I don't mind you copy / pasting it really, but it fucking pisses me off that you don't at least give credit to the original link. (Here, by the way.[^])
and you could have posted the second entry on that page as well...
How to open a PowerPoint Show (*.pps) file thru code
It's fairly simple to open a PowerPoint file (*.ppt) for editing using VBA code however opening a PowerPoint Show (*.pps) file for editing is altogether another matter. Use the Presentation.Open method and it defaults to open the file in Slide Show mode. This might not be desirable. The routine below illustrates a manner of woring around the default behaviour and opening the file for editing. The routine also illustrates the use of the ScreenUpdating property (code listed above).
' --------------------------------------------------------------------------------
' Copyright ©1999-2009, Shyam Pillai, All Rights Reserved.
' --------------------------------------------------------------------------------
' You are free to use this code within your own applications, add-ins,
' documents etc but you are expressly forbidden from selling or
' otherwise distributing this source code without prior consent.
' This includes both posting free demo projects made from this
' code as well as reproducing the code in text or html format.
' --------------------------------------------------------------------------------
Sub OpenPPSForEdit()
On Error GoTo ErrHandle
Dim pShow As Presentation
' Lock the window to prevent refreshing
' See above article example for the code
ScreenUpdating = False
'Open the show, however use additional flag - WithWindow set to FALSE
Set pShow = Presentations.Open("C:\sample.pps", _
WithWindow:=msoFalse)
'Open a window now to the presentation for editing
pShow.NewWindow
' Unlock the window to start refreshing again
ScreenUpdating = True
Exit Sub
ErrHandle:
If Err.Number <> 0 Then
MsgBox Err.Number & " " & Err.Description, _
vbCritical + vbOKOnly, "Error"
End If
End Sub
|
|
|
|
|
I'm very sorry but I haven't read the remarques completly. It was my wrong thinking that it was already in the remarques. I read more carfully in the future.
However al that other code came also from internet.
|
|
|
|
|