MS Access does not recognize "classic" VBA functions - forms

I am using the following function to vertically align labels in a form.
Private Sub VerticallyCenter(ctl As control)
Dim lngHeight As Long
lngHeight = fTextHeight(ctl)
' Rounding will result in a 1 to 2 pixel margin of error
' of every control before it renders text.
ctl.TopMargin = ((ctl.Height - lngHeight) / 2)
End Sub
However, when I compile it, it says that fTextHeight() is not defined. I have the same error on other "classic" VBA Access functions as DirectCast() or CType(). It looks like my Access is not loading VBA Libraries.

Found it!
Like I said, fTextHeight is a custom function. It is contained in the module modTextHeightWidth in the zipped .mdb downloadable from here: http://www.lebans.com/textwidth-height.htm

Related

How can I create a Hierarchical block with GNURadio Companion?

I am trying to create a Hierarchical block using the GNURadio Companion GUI. Answers I've found in other posts say to select the blocks you want to incorporate, then go to More -> Create Hier. Then a new screen is supposed to appear. However, doing "Create Hier" with any combinations of blocks selected seems to do nothing.
Am I doing something wrong, or is there a problem with my GRC?
It's very simple. You just start with a new flow graph in GRC, and use Pad Sources as input, and Pad Sinks as output.
If you want to let the user configure something, use a Parameter GRC block.
You must set the Generate Options in the Options block to Hier Block, and set a sensible ID there, too – don't stick with top_block, but use something (without spaces or -; it needs to work as a python name) that won't conflict with something else.
Here's an example:
You can then Generate button (or press [F5]), and then, after you've done a rescan of your block library with the refresh button you can find (and use) your new block in the Block Category you specified.

I don't have MS Word installed on my system, is there a way to use/include MS Word reference to be included in my VB 6 program?

I don't have MS Word installed on my system, is there a way to use and/or an MS Word reference in my VB 6 program?
No, the use Word automation always requires that Word is installed on the system.
Depending on what you are trying to achieve there are multiple alternatives though:
OpenXML SDK: For basically anything that does not require the document to be rendered (e.g. conversion to PDF does require rendering), you can directly manipulate the contents of the file using the API provided by the SDK. As the SDK is independent of Word/Office, you can use this approach anywhere you like, be it client-side or on the server, e.g. for server-side document creation and manipulation.
Word Automation Services: If you are within SharePoint and you need to manipulate or convert documents, then this would be the tool of choice.
Third-party libraries: For instance, Aspose offers a great library for automating and converting Office documents.
You can do this by using late binding. You can write code to use Word by dimming an object variable and using CreateObject to create a Word Application object, but you can't debug it. Like #Dirk Vollmar says, it depends on what you're trying to do as to whether this makes you life inconvenient, or a nightmare.
Here is a slightly modified version of a code sample from https://support.microsoft.com/en-us/kb/177097
Sub RunWord()
Dim wObj as Object 'must use object instead of Word.Application because Word is not installed
On Error Resume Next
' Get existing instance of Word if it exists.
Set wObj = GetObject(, "Word.Application")
If Err <> 0 then
' If GetObject fails, then use CreateObject instead.
Set wObj = CreateObject("Word.Application")
End If
' Add a new document.
wObj.Documents.Add
' Exit Word.
wObj.Quit
' Clear object memory.
Set wObj = Nothing
End Sub

Is it possible to use a control without putting it on a form in VB6?

I'm pretty sure about the answer to this, but I'm trying a variety of things to get a very stubborn project to work. One idea was to try to run code through a control without defining it on a form.
So, for example, my original code looked like this:
frmProcess.MyViewer.MaxPageSize = 100
frmProcess.MyViewer.ResetPages
frmProcess.MyViewer.AddPageToView "C:\TestPage1.txt"
I've changed it to:
Dim objViewer As MyViewer
objViewer.MaxPageSize = 100
objViewer.ResetPages
objViewer.AddPageToView "C:\TestPage1.txt"
I get an error window with "Run-time error '91': Object variable or With block variable not set".
But there doesn't seem to be a way to 'set' this control. Is this just impossible, or is there another way to do it that doesn't require a form?
EDIT: I ended up abandoning this entire path of activity, as an alternate solution was found that got around the problem I was having with this form freezing. I don't want to delete this question in case someone else comes along and can benefit from the answers, which are potentially useful.
Try this on a form.
Dim objViewer As MyViewer
Set objViewer = Controls.Add("MyViewer", "MyViewer1")
objViewer.MaxPageSize = 100
objViewer.ResetPages
objViewer.AddPageToView "C:\TestPage1.txt"
I've had similar situations in the past. If all else fails and you have to use a form you can do something crude like
1) Set the .Left property of the control to a negative number (like -10000) so the control doesn't appear on the form, the user can not see it
2) Make the entire form not visible..
ActiveX controls normally expect a number of services from their containers, for example persistence. They are also "packaged and marked" in ways that set the kinds of instantiation they support.
See Introduction to ActiveX Controls.
While it is perfectly possible for a control to be created in such a way as to make many of the available services optional, most controls are created from template code that requires a number of them. And most controls that are "visible at runtime" are going to require container services.
However that doesn't mean a control can't be designed to support containerless instantiation. A well known example of such a control is Microsoft Script Control 1.0 (MSScriptControl.ScriptControl) which can be used either way.

Unicode and PDF tooltips / messageboxes with iTextSharp

I need to find a way to add a quite long string in a quite small space in a PDF document.
I am using iTextSharp. I have already tried adding comment annotations (balloons) with PdfAnnotation.CreateText() and I didn't like the way they looked/worked. It made the page too heavy (I had many comments per page) and their behavior was odd in many ways (thank Adobe for that).
Now I was thinking of adding some simple tooltips on 'chunks' in the page or popping-up messageboxes with javascript (like illustrated here : http://www.codehacker.com/ITEXTSHARP/chap15.aspx#). To my great disappointment however, it seems that Acrobat (?) doesn't support Unicode characters in those situations. E.g. I do this:
var javascript = new PdfAnnotation(
w, 200f, 550f, 300f, 650f,
PdfAction.JavaScript("app.alert('" + "Αρνάκι άσπρο και παχύ!" + "');\r", w));
chunk.SetAnnotation(javascript);
...and, in the best case, a messagebox with gibberish pops up when the user clicks on the chunk.
Is there any setting for making Unicode acceptable for the code above or another way to do what I want?
EDIT:
I have now seen this: https://stackoverflow.com/a/163065/964053
and I've tried modifying my code like that:
var javascript = new PdfAnnotation(
w, 200f, 550f, 300f, 650f,
PdfAction.JavaScript((char)0xFEFF + "app.alert('" + "Αρνάκι άσπρο και παχύ!" + "');\r", w));
chunk.SetAnnotation(javascript);
But nothing seems to change...
EDIT2 :
Using octal representation e.g. (\141) doesn't seem to help either...
EDIT3 :
This seems to work nice until you double clink on it, but I need to make the tooltip size itself based on the contents size:
var lToolTip = PdfFormField.CreatePopup(
w, new Rectangle(tc.Left, tc.Bottom, tc.Right, tc.Top), val, true);
chunk.SetAnnotation(lToolTip);
The rectangle provided doesn't seem to be used in any way...
Any ideas?
I don't know what PdfFormField.CreatePopup() is supposed to create, but I see a small mark on my page that displays a popup when you hover the mouse over it.
I'm kind of lost in your edits, it's not clear what works for you and what doesn't, but regarding the unicode problem in JavaScript: are you aware that there are two versions of the javaScript() method?
See javaScript(java.lang.String, com.itextpdf.text.pdf.PdfWriter, boolean)
If you add the boolean value true, the JavaScript string should be interpreted as Unicode. If this doesn't solve your problem, I'll delete this answer, and if you clarify your question (cutting away the irrelevant parts), I'll do another attempt.

Integrate Stack Overflow into IDEs?

Okay, this is just a crazy idea I have. Stack Overflow looks very structured and integrable into development applications. So would it be possible, even useful, to have a Stack Overflow plugin for, say, Eclipse?
Which features of Stack Overflow would you like to have directly integrated into your IDE so you can use it "natively" without changing to a browser?
EDIT: I'm thinking about ways of deeper integration than just using the web page inside the IDE. Like when you use a certain Java class and have a problem, answers from SO might flare up. There would probably be cases where something like this is annoying, but others may be very helpful.
Following up on Josh's answer. This VS Macro will search StackOverflow for highlighted text in the Visual Studio IDE. Just highlight and press Alt+F1
Public Sub SearchStackOverflowForSelectedText()
Dim s As String = ActiveWindowSelection().Trim()
If s.Length > 0 Then
DTE.ItemOperations.Navigate("http://www.stackoverflow.com/search?q=" & _
Web.HttpUtility.UrlEncode(s))
End If
End Sub
Private Function ActiveWindowSelection() As String
If DTE.ActiveWindow.ObjectKind = EnvDTE.Constants.vsWindowKindOutput Then
Return OutputWindowSelection()
End If
If DTE.ActiveWindow.ObjectKind = "{57312C73-6202-49E9-B1E1-40EA1A6DC1F6}" Then
Return HTMLEditorSelection()
End If
Return SelectionText(DTE.ActiveWindow.Selection)
End Function
Private Function HTMLEditorSelection() As String
Dim hw As HTMLWindow = ActiveDocument.ActiveWindow.Object
Dim tw As TextWindow = hw.CurrentTabObject
Return SelectionText(tw.Selection)
End Function
Private Function OutputWindowSelection() As String
Dim w As Window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)
Dim ow As OutputWindow = w.Object
Dim owp As OutputWindowPane = ow.OutputWindowPanes.Item(ow.ActivePane.Name)
Return SelectionText(owp.TextDocument.Selection)
End Function
Private Function SelectionText(ByVal sel As EnvDTE.TextSelection) As String
If sel Is Nothing Then
Return ""
End If
If sel.Text.Length = 0 Then
SelectWord(sel)
End If
If sel.Text.Length <= 2 Then
Return ""
End If
Return sel.Text
End Function
Private Sub SelectWord(ByVal sel As EnvDTE.TextSelection)
Dim leftPos As Integer
Dim line As Integer
Dim pt As EnvDTE.EditPoint = sel.ActivePoint.CreateEditPoint()
sel.WordLeft(True, 1)
line = sel.TextRanges.Item(1).StartPoint.Line
leftPos = sel.TextRanges.Item(1).StartPoint.LineCharOffset
pt.MoveToLineAndOffset(line, leftPos)
sel.MoveToPoint(pt)
sel.WordRight(True, 1)
End Sub
To install:
go to Tools - Macros - IDE
create a new Module with a name of your choice under "MyMacros". Or use an existing module.
paste the above code into the module
add a reference to the System.Web namespace (for HttpUtility) to the module
close the macro IDE window
go to Tools - Options - Environment - Keyboard
type "google" in the Show Commands Containing textbox. The SearchGoogleForSelectedText macro should show up
click in the Press Shortcut Keys textbox, then press ALT+F1
click the Assign button
click OK
This is all taken from Jeff Atwood's Google Search VS Macro post, just modified to search StackOverflow instead.
I don't think I'll be able to get any work done with SO integrated into an IDE. Its almost as bad, if not worst than integrating Digg/Reddit into an IDE.
In Visual Studio, you could add a shortcut to search for a highlighted term in StackOverflow. Jeff Atwood wrote about doing something similar with Google in his Google search VS.NET macro blog entry.
Using this approach would allow you to highlight a term or error message (or any other selectable text in the IDE), press the shortcut keys, and then see all the matching results on StackOverflow.
I'm sure there's a way to do this in other IDE's as well.
If StackOverflow can begin identifying the language that each code snippet contains, then I could see an code-completion/code-snippet plugin to an IDE that responds to a special syntax for performing searches on SO and inserting the code portion of accepted answers.
Eg: in my source I might type:
//# read an XML file
The //# syntax prompts the plugin to start a search and display a list of question titles. When I pick one, it inserts the code portion of the accepted answer.
I don't know about Eclipse, but for Visual Studio, if someone really wanted this they could easily add the SO RSS feed for the "Start Page News Channel" so the SO question list appeared in the start page, or even better, narrow it down with a tag (like for C#). It's not exactly "integration", but it would provide a quick look at recent things with extremely little effort. However, not sure how "useful" it would be.
You have the RSS plugin for Eclipse to read the StackOverflow feed.
But I'm with you, a SO Eclipse plugin would be really cool.
You could just set it as your Start Page in Visual Studio.
Not sure what benefit this would provide... but to each his own.