A federal judge in Alexandria yesterday dismissed a suit filed by former shareholders in the Bank of Vienna, ruling that several officers and directors of the bank violated no laws in the spring of 1981 when they quietly bought bank stock without revealing that they were the purchasers.

The officers and directors, who formed a partnership called HGM, paid about $17 for the stock in the spring of 1981. Late last year, after a spate of competing merger offers, the Bank of Virginia paid $40 a share to buy the suburban Virginia bank.

The former shareholders--Maurice and Virginia Fox and M. Patton Echols Jr.--initially sued the six HGM partners to recover the stock for the price they sold it for, then amended the suit to ask for the difference between the selling price and the $40 a share the HGM partners received from Bank of Virginia.

Judge Albert V. Bryan Jr. ruled yesterday that he found no evidence of insider trading or any breach of fiduciary responsibility to shareholders on the part of the officers and directors in HGM.

The partners in HGM included the bank's president, H.E. McCarty; the bank's principal shareholder, Meyer H. Abraham, Abraham's son; the bank's executive vice president and two other directors.

The partnership bought about 3,000 shares of Bank of Vienna stock before informing other members of the board of their activities. The partnership was dissolved after other directors expressed their displeasure with the HGM activities.

But the partnership sparked a split on the bank's 10-member board of directors that eventually left the $25 million institution open to a takeover. The bank's former chairman, Michael Juhasz, angered by HGM's unannounced purchases of Bank of Vienna, agreed to sell his holdings to Bank of Virginia.

Wyatt B. Durrette, lawyer for the HGM partners, has said that HGM bought the stock to keep it from falling into unfriendly hands. He said they wanted to ensure the bank remained independent.